Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: rewrite cron to use async system #2407

Merged
merged 15 commits into from
Aug 23, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: cron using async
safeer committed Aug 23, 2024
commit 2c1ae61b2d2f010fc25383beb0fa43e6cd2d5e13
2 changes: 1 addition & 1 deletion Justfile
Original file line number Diff line number Diff line change
@@ -75,7 +75,7 @@ init-db:

# Regenerate SQLC code (requires init-db to be run first)
build-sqlc:
@mk backend/controller/sql/{db.go,models.go,querier.go,queries.sql.go} backend/controller/{cronjobs}/sql/{db.go,models.go,querier.go,queries.sql.go} internal/configuration/sql/{db.go,models.go,querier.go,queries.sql.go} : backend/controller/sql/queries.sql backend/controller/{cronjobs}/sql/queries.sql internal/configuration/sql/queries.sql backend/controller/sql/schema sqlc.yaml -- "just init-db && sqlc generate"
@mk backend/controller/sql/{db.go,models.go,querier.go,queries.sql.go} backend/controller/cronjobs/sql/{db.go,models.go,querier.go,queries.sql.go} common/configuration/sql/{db.go,models.go,querier.go,queries.sql.go} : backend/controller/sql/queries.sql backend/controller/cronjobs/sql/queries.sql common/configuration/sql/queries.sql backend/controller/sql/schema sqlc.yaml -- "just init-db && sqlc generate"

# Build the ZIP files that are embedded in the FTL release binaries
build-zips: build-kt-runtime
17 changes: 14 additions & 3 deletions backend/controller/controller.go
Original file line number Diff line number Diff line change
@@ -249,9 +249,8 @@ func New(ctx context.Context, conn *sql.DB, config Config, runnerScaling scaling
svc.routes.Store(map[string][]dal.Route{})
svc.schema.Store(&schema.Schema{})

cronSvc := cronjobs.New(ctx, key, svc.config.Advertise.Host, cronjobs.Config{Timeout: config.CronJobTimeout}, conn, svc.tasks, svc.callWithRequest)
cronSvc := cronjobs.New(ctx, key, svc.config.Advertise.Host, conn)
svc.cronJobs = cronSvc
svc.controllerListListeners = append(svc.controllerListListeners, cronSvc)

pubSub := pubsub.New(ctx, db, svc.tasks, svc)
svc.pubSub = pubSub
@@ -541,7 +540,7 @@ func (s *Service) ReplaceDeploy(ctx context.Context, c *connect.Request[ftlv1.Re
}
}

s.cronJobs.CreatedOrReplacedDeloyment(ctx, newDeploymentKey)
s.cronJobs.CreatedOrReplacedDeloyment(ctx)

return connect.NewResponse(&ftlv1.ReplaceDeployResponse{}), nil
}
@@ -1568,6 +1567,9 @@ func (s *Service) catchAsyncCall(ctx context.Context, logger *log.Logger, call *

func metadataForAsyncCall(call *dal.AsyncCall) *ftlv1.Metadata {
switch origin := call.Origin.(type) {
case dal.AsyncOriginCron:
return &ftlv1.Metadata{}

case dal.AsyncOriginFSM:
return &ftlv1.Metadata{
Values: []*ftlv1.Metadata_Pair{
@@ -1595,6 +1597,15 @@ func (s *Service) finaliseAsyncCall(ctx context.Context, tx *dal.Tx, call *dal.A

// Allow for handling of completion based on origin
switch origin := call.Origin.(type) {
case dal.AsyncOriginCron:
cjk, err := model.ParseCronJobKey(origin.CronJobKey)
if err != nil {
return fmt.Errorf("failed to parse cron job key: %w", err)
}
if err := s.cronJobs.OnJobCompletion(ctx, cjk, failed); err != nil {
return fmt.Errorf("failed to finalize cron async call: %w", err)
}

case dal.AsyncOriginFSM:
if err := s.onAsyncFSMCallCompletion(ctx, tx, origin, failed, isFinalResult); err != nil {
return fmt.Errorf("failed to finalize FSM async call: %w", err)
Loading