-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from zachmarshall/master
Add handlers for email, transfer, visitation, and reminders.
- Loading branch information
Showing
29 changed files
with
564 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
.env | ||
.idea | ||
.idea | ||
TaskRunner |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
module JobScheduler | ||
module github.com/vatusa/taskrunner | ||
|
||
go 1.21 | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package email | ||
|
||
type Payload struct { | ||
DestinationAddress string `json:"destinationAddress"` // Receiver's email address | ||
CCAddresses []string `json:"ccAddresses"` // CC email addresses | ||
Subject string `json:"subject"` // Email subject | ||
Body string `json:"body"` // Email body | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
package email | ||
package handler | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
|
||
"github.com/vatusa/taskrunner/pkg/email" | ||
|
||
"github.com/sendgrid/sendgrid-go" | ||
"github.com/sendgrid/sendgrid-go/helpers/mail" | ||
) | ||
|
||
func SendEmail(payload Payload) error { | ||
func SendEmail(payload email.Payload) error { | ||
from := mail.NewEmail("VATUSA Mailman", "[email protected]") | ||
subject := payload.Subject | ||
to := mail.NewEmail("", payload.DestinationAddress) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package dispatcher | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/vatusa/taskrunner/internal/logger" | ||
"github.com/vatusa/taskrunner/pkg/email" | ||
emailHandler "github.com/vatusa/taskrunner/pkg/email/handler" | ||
"github.com/vatusa/taskrunner/pkg/jobs" | ||
"github.com/vatusa/taskrunner/pkg/reminders" | ||
remindersHandler "github.com/vatusa/taskrunner/pkg/reminders/handler" | ||
"github.com/vatusa/taskrunner/pkg/transfer" | ||
transferHandler "github.com/vatusa/taskrunner/pkg/transfer/handler" | ||
"github.com/vatusa/taskrunner/pkg/visit" | ||
visitHandler "github.com/vatusa/taskrunner/pkg/visit/handler" | ||
) | ||
|
||
// JobDispatcher dispatches jobs to the appropriate handlers | ||
type JobDispatcher struct { | ||
// Add fields if needed, like logger, config, etc. | ||
} | ||
|
||
func NewJobDispatcher() *JobDispatcher { | ||
return &JobDispatcher{} | ||
} | ||
|
||
func (d *JobDispatcher) Dispatch(j jobs.Job) (jobs.Job, error) { | ||
logger.Info("dispatching job: ", j.ID) | ||
|
||
switch j.Type { | ||
case jobs.EmailJob: | ||
return d.handleEmailJob(j) | ||
case jobs.TransferStartedJob: | ||
return d.handleTransferStartedJob(j) | ||
case jobs.TransferStateChangeJob: | ||
return d.handleTransferStateChangeJob(j) | ||
case jobs.VisitStartedJob: | ||
return d.handleVisitStartedJob(j) | ||
case jobs.VisitStateChangeJob: | ||
return d.handleVisitStateChangeJob(j) | ||
case jobs.ReminderJob: | ||
return d.handleReminderJob(j) | ||
|
||
// Add cases for other job types | ||
|
||
default: | ||
errMsg := fmt.Errorf("unsupported job type: %s", j.Type) | ||
logger.Error(errMsg) | ||
return jobs.Job{}, errMsg | ||
} | ||
} | ||
|
||
func (d *JobDispatcher) handleEmailJob(j jobs.Job) (jobs.Job, error) { | ||
emailJobPayload, ok := j.Payload.(email.Payload) | ||
if !ok { | ||
return jobs.Job{}, fmt.Errorf("invalid payload for email job") | ||
} | ||
|
||
return jobs.Job{}, emailHandler.SendEmail(emailJobPayload) | ||
} | ||
|
||
func (d *JobDispatcher) handleTransferStartedJob(j jobs.Job) (jobs.Job, error) { | ||
transferPayload, ok := j.Payload.(transfer.Transfer) | ||
if !ok { | ||
return jobs.Job{}, fmt.Errorf("invalid payload for transfer job") | ||
} | ||
|
||
return transferHandler.HandleTransferStarted(transferPayload) | ||
} | ||
|
||
func (d *JobDispatcher) handleTransferStateChangeJob(j jobs.Job) (jobs.Job, error) { | ||
transferPayload, ok := j.Payload.(transfer.TransferStateChange) | ||
if !ok { | ||
return j, fmt.Errorf("invalid payload for transfer job") | ||
} | ||
|
||
return transferHandler.HandleTransferStateChange(transferPayload) | ||
} | ||
|
||
func (d *JobDispatcher) handleVisitStartedJob(j jobs.Job) (jobs.Job, error) { | ||
visitPayload, ok := j.Payload.(visit.Visit) | ||
if !ok { | ||
return j, fmt.Errorf("invalid payload for visit job") | ||
} | ||
|
||
return visitHandler.HandleVisitStarted(visitPayload) | ||
} | ||
|
||
func (d *JobDispatcher) handleVisitStateChangeJob(j jobs.Job) (jobs.Job, error) { | ||
visitPayload, ok := j.Payload.(visit.VisitStateChange) | ||
if !ok { | ||
return j, fmt.Errorf("invalid payload for visit state change job") | ||
} | ||
|
||
return visitHandler.HandleVisitStateChange(visitPayload) | ||
} | ||
|
||
func (d *JobDispatcher) handleReminderJob(j jobs.Job) (jobs.Job, error) { | ||
reminderPayload, ok := j.Payload.(reminders.Reminder) | ||
if !ok { | ||
return j, fmt.Errorf("invalid payload for reminder job") | ||
} | ||
|
||
return remindersHandler.HandleReminder(reminderPayload) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.