Changeset View
Changeset View
Standalone View
Standalone View
swh/scheduler/sql/40-swh-func.sql
Show First 20 Lines • Show All 299 Lines • ▼ Show 20 Lines | |||||
as $$ | as $$ | ||||
select t.id as task_id, t.policy as task_policy, | select t.id as task_id, t.policy as task_policy, | ||||
t.status as task_status, tr.id as task_run_id, | t.status as task_status, tr.id as task_run_id, | ||||
t.arguments, t.type, tr.backend_id, tr.metadata, | t.arguments, t.type, tr.backend_id, tr.metadata, | ||||
tr.scheduled, tr.started, tr.ended, tr.status as task_run_status | tr.scheduled, tr.started, tr.ended, tr.status as task_run_status | ||||
from task_run tr inner join task t on tr.task=t.id | from task_run tr inner join task t on tr.task=t.id | ||||
where ((t.policy = 'oneshot' and t.status in ('completed', 'disabled')) or | where ((t.policy = 'oneshot' and t.status in ('completed', 'disabled')) or | ||||
(t.policy = 'recurring' and t.status = 'disabled')) and | (t.policy = 'recurring' and t.status = 'disabled')) and | ||||
((ts_after <= tr.started and tr.started < ts_before) or tr.started is null) and | ((ts_after <= tr.started and tr.started < ts_before) or | ||||
ardumont: Prior to this, the actual filtering ended up listing tasks completely out of the input range. | |||||
t.id > last_id | (tr.started is null and (ts_after <= tr.scheduled and tr.scheduled < ts_before))) and | ||||
t.id >= last_id | |||||
order by tr.task, tr.started | order by tr.task, tr.started | ||||
limit lim; | limit lim; | ||||
$$; | $$; | ||||
comment on function swh_scheduler_task_to_archive (timestamptz, timestamptz, bigint, bigint) is 'Read archivable tasks function'; | comment on function swh_scheduler_task_to_archive (timestamptz, timestamptz, bigint, bigint) is 'Read archivable tasks function'; | ||||
create or replace function swh_scheduler_delete_archived_tasks( | create or replace function swh_scheduler_delete_archived_tasks( | ||||
task_ids bigint[], task_run_ids bigint[]) | task_ids bigint[], task_run_ids bigint[]) | ||||
▲ Show 20 Lines • Show All 82 Lines • ▼ Show 20 Lines | |||||
end; | end; | ||||
$$; | $$; | ||||
create trigger update_task_on_task_end | create trigger update_task_on_task_end | ||||
after update of status on task_run | after update of status on task_run | ||||
for each row | for each row | ||||
when (new.status NOT IN ('scheduled', 'started')) | when (new.status NOT IN ('scheduled', 'started')) | ||||
execute procedure swh_scheduler_update_task_on_task_end (); | execute procedure swh_scheduler_update_task_on_task_end (); | ||||
Prior to this, the actual filtering ended up listing tasks completely out of the input range.
Because we have tasks with started column left null (they never started).
Those have the scheduled entry set so we use it for filtering (which was already done client side in the task cli).
Now we are consistent.
And we will finally be able to filter those out of the scheduler db.