OXYGENHUB
◆ v0.9.7 oxygenhub / crates / hub / migrations-pg / 0080_flow_job_times.sql
1.0 KiB · SQL · last changed Insights: OxygenFlow's standard charts, for the site, an owner and a repository 17 days ago source blame history raw
1
-- When a job entered the queue and when it became ready to run
2
-- (oxygenhub#257): its pickup time is started_ms - ready_ms. queued_ms is
3
-- set when the job is made and when it is run again; ready_ms when a
4
-- runner claims it: the latest of queued_ms, its dependencies finishing
5
-- and its approval.
6
ALTER TABLE flow_jobs ADD COLUMN queued_ms BIGINT;
7
ALTER TABLE flow_jobs ADD COLUMN ready_ms BIGINT;
8
-- Earlier jobs: queued with their run, ready once the stages before
9
-- theirs had finished (a job runs again keeps its run's time: an estimate).
10
UPDATE flow_jobs SET queued_ms = (SELECT r.created_ms FROM flow_runs r WHERE r.id = flow_jobs.run_id);
11
UPDATE flow_jobs SET ready_ms = LEAST(started_ms, GREATEST(queued_ms, COALESCE(approved_ms, 0),
12
    COALESCE((SELECT MAX(x.finished_ms) FROM flow_jobs x WHERE x.run_id = flow_jobs.run_id AND x.depth < flow_jobs.depth), 0)))
13
  WHERE started_ms IS NOT NULL;
14
CREATE INDEX flow_jobs_started ON flow_jobs (started_ms);
15
CREATE INDEX flow_jobs_finished ON flow_jobs (finished_ms);