Skip to content

Commit

Permalink
cleanup; move IsCronJobPending, remove extraneous params
Browse files Browse the repository at this point in the history
  • Loading branch information
safeer committed Aug 22, 2024
1 parent 7810fc8 commit 25c32ae
Show file tree
Hide file tree
Showing 7 changed files with 51 additions and 56 deletions.
11 changes: 4 additions & 7 deletions backend/controller/cronjobs/cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,10 @@ func (s *Service) scheduleCronJob(ctx context.Context, tx *Tx, job model.CronJob

logger.Tracef("Scheduling cron job %q async_call execution at %s", job.Key, nextAttemptForJob)
id, err := tx.db.CreateAsyncCall(ctx, cronsql.CreateAsyncCallParams{
ScheduledAt: nextAttemptForJob,
Verb: schema.RefKey{Module: job.Verb.Module, Name: job.Verb.Name},
Origin: fmt.Sprintf("cron:%s", job.Key),
Request: []byte(`{}`),
RemainingAttempts: 0,
Backoff: 0,
MaxBackoff: 0,
ScheduledAt: nextAttemptForJob,
Verb: schema.RefKey{Module: job.Verb.Module, Name: job.Verb.Name},
Origin: fmt.Sprintf("cron:%s", job.Key),
Request: []byte(`{}`),
})
if err != nil {
return fmt.Errorf("failed to create async call for job %q: %w", job.Key, err)
Expand Down
19 changes: 0 additions & 19 deletions backend/controller/cronjobs/sql/async_queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 11 additions & 1 deletion backend/controller/cronjobs/sql/queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,14 @@ UPDATE cron_jobs
SET last_async_call_id = sqlc.arg('last_async_call_id')::BIGINT,
last_execution = sqlc.arg('last_execution')::TIMESTAMPTZ,
next_execution = sqlc.arg('next_execution')::TIMESTAMPTZ
WHERE key = sqlc.arg('key')::cron_job_key;
WHERE key = sqlc.arg('key')::cron_job_key;

-- name: IsCronJobPending :one
SELECT EXISTS (
SELECT 1
FROM cron_jobs j
INNER JOIN async_calls ac on j.last_async_call_id = ac.id
WHERE j.key = sqlc.arg('key')::cron_job_key
AND ac.scheduled_at > sqlc.arg('start_time')::TIMESTAMPTZ
AND ac.state = 'pending'
) AS pending;
18 changes: 18 additions & 0 deletions backend/controller/cronjobs/sql/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 0 additions & 10 deletions backend/controller/sql/async_queries.sql
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,3 @@ VALUES (
@trace_context::jsonb
)
RETURNING id;

-- name: IsCronJobPending :one
SELECT EXISTS (
SELECT 1
FROM cron_jobs j
INNER JOIN async_calls ac on j.last_async_call_id = ac.id
WHERE j.key = sqlc.arg('key')::cron_job_key
AND ac.scheduled_at > sqlc.arg('start_time')::TIMESTAMPTZ
AND ac.state = 'pending'
) AS pending;
19 changes: 0 additions & 19 deletions backend/controller/sql/async_queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions backend/controller/sql/queries.sql.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 25c32ae

Please sign in to comment.