Skip to content

Commit

Permalink
fix: cron deployment key
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas committed Dec 18, 2024
1 parent c6b2b27 commit 5027228
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
31 changes: 20 additions & 11 deletions backend/cron/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,12 @@ import (
)

type cronJob struct {
module string
verb *schema.Verb
cronmd *schema.MetadataCronJob
pattern cron.Pattern
next time.Time
module string
deployment model.DeploymentKey
verb *schema.Verb
cronmd *schema.MetadataCronJob
pattern cron.Pattern
next time.Time
}

type Config struct {
Expand Down Expand Up @@ -133,7 +134,7 @@ func scheduleNext(ctx context.Context, cronQueue []cronJob, timelineClient *time
return 0, false
}
timelineClient.Publish(ctx, timeline.CronScheduled{
DeploymentKey: model.NewDeploymentKey(cronQueue[0].module),
DeploymentKey: cronQueue[0].deployment,
Verb: schema.Ref{Module: cronQueue[0].module, Name: cronQueue[0].verb.Name},
ScheduledAt: cronQueue[0].next,
Schedule: cronQueue[0].pattern.String(),
Expand Down Expand Up @@ -182,6 +183,9 @@ func rebuildQueue(cronJobs map[string][]cronJob) []cronJob {
}

func extractCronJobs(module *schema.Module) ([]cronJob, error) {
if module.Runtime == nil || module.Runtime.Deployment == nil {
return nil, nil
}
cronJobs := []cronJob{}
for verb := range slices.FilterVariants[*schema.Verb](module.Decls) {
cronmd, ok := slices.FindVariant[*schema.MetadataCronJob](verb.Metadata)
Expand All @@ -196,12 +200,17 @@ func extractCronJobs(module *schema.Module) ([]cronJob, error) {
if err != nil {
return nil, fmt.Errorf("%s: %w", cronmd.Pos, err)
}
deploymentKey, err := model.ParseDeploymentKey(module.Runtime.Deployment.DeploymentKey)
if err != nil {
return nil, fmt.Errorf("%s: %w", cronmd.Pos, err)
}
cronJobs = append(cronJobs, cronJob{
module: module.Name,
verb: verb,
cronmd: cronmd,
pattern: pattern,
next: next,
module: module.Name,
deployment: deploymentKey,
verb: verb,
cronmd: cronmd,
pattern: pattern,
next: next,
})
}
return cronJobs, nil
Expand Down
5 changes: 5 additions & 0 deletions backend/cron/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@ func TestCron(t *testing.T) {
eventSource := schemaeventsource.NewUnattached()
module := &schema.Module{
Name: "echo",
Runtime: &schema.ModuleRuntime{
Deployment: &schema.ModuleRuntimeDeployment{
DeploymentKey: model.NewDeploymentKey("echo").String(),
},
},
Decls: []schema.Decl{
&schema.Verb{
Name: "echo",
Expand Down

0 comments on commit 5027228

Please sign in to comment.