Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
Go
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253package db
import ( "context" "time")
func (d *DB) ClaimScheduleRun(ctx context.Context, repoDid, workflow string, scheduledAt time.Time, minimumInterval time.Duration) (bool, error) { scheduledAtUnix := scheduledAt.Unix() result, err := d.ExecContext(ctx, ` insert or ignore into schedule_runs (repo_did, workflow, scheduled_at) select ?, ?, ? where not exists ( select 1 from schedule_runs where repo_did = ? and workflow = ? and scheduled_at > ? and scheduled_at <= ? ) `, repoDid, workflow, scheduledAtUnix, repoDid, workflow, scheduledAt.Add(-minimumInterval).Unix(), scheduledAtUnix, ) if err != nil { return false, err } rows, err := result.RowsAffected() return rows == 1, err}
func (d *DB) CompleteScheduleRun(ctx context.Context, repoDid, workflow string, scheduledAt time.Time, pipelineID string) error { _, err := d.ExecContext(ctx, ` update schedule_runs set pipeline_id = ? where repo_did = ? and workflow = ? and scheduled_at = ? `, pipelineID, repoDid, workflow, scheduledAt.Unix()) return err}
func (d *DB) ReleaseScheduleRun(ctx context.Context, repoDid, workflow string, scheduledAt time.Time) error { _, err := d.ExecContext(ctx, ` delete from schedule_runs where repo_did = ? and workflow = ? and scheduled_at = ? and pipeline_id is null `, repoDid, workflow, scheduledAt.Unix()) return err}
func (d *DB) PruneScheduleRuns(ctx context.Context, before time.Time) error { _, err := d.ExecContext(ctx, `delete from schedule_runs where scheduled_at < ?`, before.Unix()) return err}