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 17, 2024
1 parent de2f528 commit 56380b4
Showing 1 changed file with 20 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

0 comments on commit 56380b4

Please sign in to comment.