mirror of
https://github.com/hatchet-dev/hatchet.git
synced 2025-12-16 22:35:11 -06:00
@@ -40,6 +40,9 @@ func main() {
|
||||
}, nil
|
||||
},
|
||||
hatchet.WithWorkflowCron("0 2 * * *"),
|
||||
hatchet.WithWorkflowCronInput(CronInput{
|
||||
Timestamp: time.Now().Format(time.RFC3339),
|
||||
}),
|
||||
hatchet.WithWorkflowDescription("Daily cleanup and maintenance tasks"),
|
||||
)
|
||||
// !!
|
||||
|
||||
@@ -119,6 +119,7 @@ type workflowDeclarationImpl[I any, O any] struct {
|
||||
Description *string
|
||||
OnEvents []string
|
||||
OnCron []string
|
||||
CronInput *string
|
||||
Concurrency []types.Concurrency
|
||||
OnFailureTask *task.OnFailureTaskDeclaration[I]
|
||||
StickyStrategy *types.StickyStrategy
|
||||
@@ -179,6 +180,7 @@ func NewWorkflowDeclaration[I any, O any](opts create.WorkflowCreateOpts[I], v0
|
||||
name: workflowName,
|
||||
OnEvents: onEvents,
|
||||
OnCron: opts.OnCron,
|
||||
CronInput: opts.CronInput,
|
||||
Concurrency: opts.Concurrency,
|
||||
// OnFailureTask: opts.OnFailureTask, // TODO: add this back in
|
||||
StickyStrategy: opts.StickyStrategy,
|
||||
@@ -588,6 +590,7 @@ func (w *workflowDeclarationImpl[I, O]) Dump() (*contracts.CreateWorkflowVersion
|
||||
Name: w.name,
|
||||
EventTriggers: w.OnEvents,
|
||||
CronTriggers: w.OnCron,
|
||||
CronInput: w.CronInput,
|
||||
DefaultPriority: w.DefaultPriority,
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"sync"
|
||||
"time"
|
||||
@@ -116,6 +117,7 @@ type workflowConfig struct {
|
||||
taskDefaults *create.TaskDefaults
|
||||
defaultPriority *RunPriority
|
||||
stickyStrategy *types.StickyStrategy
|
||||
cronInput *string
|
||||
}
|
||||
|
||||
// WithWorkflowCron configures the workflow to run on a cron schedule.
|
||||
@@ -126,6 +128,24 @@ func WithWorkflowCron(cronExpressions ...string) WorkflowOption {
|
||||
}
|
||||
}
|
||||
|
||||
// WithWorkflowCronInput sets the input for cron workflows.
|
||||
func WithWorkflowCronInput(input any) WorkflowOption {
|
||||
return func(config *workflowConfig) {
|
||||
inputJSON := "{}"
|
||||
|
||||
if input != nil {
|
||||
bytes, err := json.Marshal(input)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("could not marshal cron input: %w", err))
|
||||
}
|
||||
|
||||
inputJSON = string(bytes)
|
||||
}
|
||||
|
||||
config.cronInput = &inputJSON
|
||||
}
|
||||
}
|
||||
|
||||
// WithWorkflowEvents configures the workflow to trigger on specific events.
|
||||
func WithWorkflowEvents(events ...string) WorkflowOption {
|
||||
return func(config *workflowConfig) {
|
||||
@@ -183,12 +203,18 @@ func newWorkflow(name string, v0Client v0Client.Client, options ...WorkflowOptio
|
||||
opt(config)
|
||||
}
|
||||
|
||||
if len(config.onCron) > 0 && config.cronInput == nil {
|
||||
emptyJSON := "{}"
|
||||
config.cronInput = &emptyJSON
|
||||
}
|
||||
|
||||
createOpts := create.WorkflowCreateOpts[any]{
|
||||
Name: name,
|
||||
Version: config.version,
|
||||
Description: config.description,
|
||||
OnEvents: config.onEvents,
|
||||
OnCron: config.onCron,
|
||||
CronInput: config.cronInput,
|
||||
Concurrency: config.concurrency,
|
||||
TaskDefaults: config.taskDefaults,
|
||||
StickyStrategy: config.stickyStrategy,
|
||||
|
||||
Reference in New Issue
Block a user