diff --git a/starter/example/workflow.go b/starter/example/workflow.go index 55a52f3..17efdb8 100644 --- a/starter/example/workflow.go +++ b/starter/example/workflow.go @@ -1,21 +1,44 @@ package example import ( + "context" + + "git.gorlug.de/code/ersteller/queue" "git.gorlug.de/code/ersteller/schema/ent" . "git.gorlug.de/code/ersteller/workflow" ) func CreateExampleWorkflow(client *ent.Client) { - step := NewStep(&StepParams{ - Name: "Initial step", - Identifier: "initial_step", - Description: "Initial step", - Client: client, - MaxRetries: 3, - Handler: , - + lastStep := NewStep(&StepParams{ + Name: "Last step", + Identifier: "last_step", + Description: "Last step", + Client: client, + MaxRetries: 3, + Handler: func(ctx context.Context, currentStep *Step, job queue.GeneralQueueJob) (queue.GeneralQueueHandlerResult, *Step, error) { + return queue.GeneralQueueHandlerResult{ + ResultPayload: map[string]interface{}{ + "lastStep": "hello", + }, + }, nil, nil + }, }) - //w := NewWorkflow("Example", "example") + + firstStep := NewStep(&StepParams{ + Name: "Initial step", + Identifier: "initial_step", + Description: "Initial step", + Client: client, + MaxRetries: 3, + Handler: func(ctx context.Context, currentStep *Step, job queue.GeneralQueueJob) (queue.GeneralQueueHandlerResult, *Step, error) { + return queue.GeneralQueueHandlerResult{ + ResultPayload: map[string]interface{}{ + "firstStep": "hello", + }, + }, lastStep, nil + }, + }) + NewWorkflow("Example", "example", firstStep) } //type name struct { diff --git a/starter/main.go b/starter/main.go index 03a29a3..df40ad2 100644 --- a/starter/main.go +++ b/starter/main.go @@ -7,8 +7,10 @@ import ( "time" . "git.gorlug.de/code/ersteller" + erstellerEnt "git.gorlug.de/code/ersteller/schema/ent" "git.gorlug.de/code/ersteller/starter/ent" "git.gorlug.de/code/ersteller/starter/env" + "git.gorlug.de/code/ersteller/starter/example" "git.gorlug.de/code/ersteller/starter/routes" ) @@ -24,6 +26,21 @@ func main() { } log.Println("client", client) defer client.Close() + err = client.Schema.Create(context.Background()) + if err != nil { + log.Fatalf("failed creating schema resources: %v", err) + } + + entClient, err := erstellerEnt.Open("sqlite3", environment.DatabaseUrl) + if err != nil { + log.Fatalf("failed opening connection to sqlite: %v", err) + } + defer entClient.Close() + err = entClient.Schema.Create(context.Background()) + if err != nil { + log.Fatalf("failed creating schema resources: %v", err) + } + example.CreateExampleWorkflow(entClient) ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5) defer cancel() diff --git a/workflow/workflow.go b/workflow/workflow.go index 4888ec5..264b9e4 100644 --- a/workflow/workflow.go +++ b/workflow/workflow.go @@ -10,10 +10,8 @@ import ( "git.gorlug.de/code/ersteller/schema/ent" ) -type StepHandler interface { - Handle(ctx context.Context, currentStep *Step, - job queue.GeneralQueueJob) (queue.GeneralQueueHandlerResult, *Step, error) -} +type StepHandler func(ctx context.Context, currentStep *Step, + job queue.GeneralQueueJob) (queue.GeneralQueueHandlerResult, *Step, error) type StepParams struct { Name string @@ -60,7 +58,7 @@ func (s *Step) Execute(ctx context.Context, payload map[string]interface{}) erro } func (s *Step) HandleQueue(ctx context.Context, job queue.GeneralQueueJob) (queue.GeneralQueueHandlerResult, error) { - result, nextStep, err := s.Handler.Handle(ctx, s, job) + result, nextStep, err := s.Handler(ctx, s, job) if err != nil { return result, err }