perf(scheduler): harden jobs for scalable execution
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/jackc/pgx/v5"
|
||||
"github.com/jackc/pgx/v5/pgxpool"
|
||||
@@ -188,6 +189,25 @@ func (r *SchedulerRepository) GetJobForRuntime(ctx context.Context, key string)
|
||||
WHERE j.job_key = $1`, key))
|
||||
}
|
||||
|
||||
func (r *SchedulerRepository) LastAutoRunStartedAt(ctx context.Context, key string) (time.Time, bool, error) {
|
||||
var startedAt time.Time
|
||||
err := r.pool.QueryRow(ctx, `
|
||||
SELECT started_at
|
||||
FROM ops.scheduler_job_runs
|
||||
WHERE job_key = $1
|
||||
AND trigger_type = 'auto'
|
||||
ORDER BY started_at DESC, id DESC
|
||||
LIMIT 1
|
||||
`, key).Scan(&startedAt)
|
||||
if err != nil {
|
||||
if errors.Is(err, pgx.ErrNoRows) {
|
||||
return time.Time{}, false, nil
|
||||
}
|
||||
return time.Time{}, false, err
|
||||
}
|
||||
return startedAt, true, nil
|
||||
}
|
||||
|
||||
func (r *SchedulerRepository) UpdateJob(ctx context.Context, key string, in SchedulerJobUpdate) (*domain.SchedulerJob, error) {
|
||||
configJSON, err := marshalSchedulerJSONMap(in.Config)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user