Create example workflow
This commit is contained in:
@@ -1,21 +1,44 @@
|
|||||||
package example
|
package example
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
|
|
||||||
|
"git.gorlug.de/code/ersteller/queue"
|
||||||
"git.gorlug.de/code/ersteller/schema/ent"
|
"git.gorlug.de/code/ersteller/schema/ent"
|
||||||
. "git.gorlug.de/code/ersteller/workflow"
|
. "git.gorlug.de/code/ersteller/workflow"
|
||||||
)
|
)
|
||||||
|
|
||||||
func CreateExampleWorkflow(client *ent.Client) {
|
func CreateExampleWorkflow(client *ent.Client) {
|
||||||
step := NewStep(&StepParams{
|
lastStep := NewStep(&StepParams{
|
||||||
Name: "Initial step",
|
Name: "Last step",
|
||||||
Identifier: "initial_step",
|
Identifier: "last_step",
|
||||||
Description: "Initial step",
|
Description: "Last step",
|
||||||
Client: client,
|
Client: client,
|
||||||
MaxRetries: 3,
|
MaxRetries: 3,
|
||||||
Handler: ,
|
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 {
|
//type name struct {
|
||||||
|
|||||||
@@ -7,8 +7,10 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
. "git.gorlug.de/code/ersteller"
|
. "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/ent"
|
||||||
"git.gorlug.de/code/ersteller/starter/env"
|
"git.gorlug.de/code/ersteller/starter/env"
|
||||||
|
"git.gorlug.de/code/ersteller/starter/example"
|
||||||
"git.gorlug.de/code/ersteller/starter/routes"
|
"git.gorlug.de/code/ersteller/starter/routes"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -24,6 +26,21 @@ func main() {
|
|||||||
}
|
}
|
||||||
log.Println("client", client)
|
log.Println("client", client)
|
||||||
defer client.Close()
|
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)
|
ctx, cancel := context.WithTimeout(context.Background(), time.Minute*5)
|
||||||
defer cancel()
|
defer cancel()
|
||||||
|
|||||||
@@ -10,10 +10,8 @@ import (
|
|||||||
"git.gorlug.de/code/ersteller/schema/ent"
|
"git.gorlug.de/code/ersteller/schema/ent"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StepHandler interface {
|
type StepHandler func(ctx context.Context, currentStep *Step,
|
||||||
Handle(ctx context.Context, currentStep *Step,
|
job queue.GeneralQueueJob) (queue.GeneralQueueHandlerResult, *Step, error)
|
||||||
job queue.GeneralQueueJob) (queue.GeneralQueueHandlerResult, *Step, error)
|
|
||||||
}
|
|
||||||
|
|
||||||
type StepParams struct {
|
type StepParams struct {
|
||||||
Name string
|
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) {
|
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 {
|
if err != nil {
|
||||||
return result, err
|
return result, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user