Skip to content

Commit

Permalink
Merge pull request #1141 from NASA-AMMOS/fix/cancel-scheduling-rq-tri…
Browse files Browse the repository at this point in the history
…gger

Add cancel trigger to scheduling request
  • Loading branch information
Mythicaeda authored Sep 14, 2023
2 parents 3aa7da3 + f444dc1 commit a97b4d0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
drop trigger cancel_pending_scheduling_rqs on scheduling_request;
drop function cancel_pending_scheduling_rqs();

call migrations.mark_migration_rolled_back('10');
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
create function cancel_pending_scheduling_rqs()
returns trigger
security definer
language plpgsql as $$
begin
update scheduling_request
set canceled = true
where status = 'pending'
and specification_id = new.specification_id;
return new;
end
$$;

create trigger cancel_pending_scheduling_rqs
before insert on scheduling_request
for each row
execute function cancel_pending_scheduling_rqs();

call migrations.mark_migration_applied('10');
1 change: 1 addition & 0 deletions scheduler-server/sql/scheduler/applied_migrations.sql
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ call migrations.mark_migration_applied('6');
call migrations.mark_migration_applied('7');
call migrations.mark_migration_applied('8');
call migrations.mark_migration_applied('9');
call migrations.mark_migration_applied('10');
22 changes: 19 additions & 3 deletions scheduler-server/sql/scheduler/tables/scheduling_request.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ comment on column scheduling_request.requested_at is e''
-- Scheduling request NOTIFY triggers
-- These triggers NOTIFY LISTEN(ing) scheduler worker clients of pending scheduling requests

create or replace function notify_scheduler_workers ()
create function notify_scheduler_workers ()
returns trigger
security definer
language plpgsql as $$
Expand All @@ -64,9 +64,25 @@ begin
return null;
end$$;

do $$ begin
create trigger notify_scheduler_workers
after insert on scheduling_request
for each row
execute function notify_scheduler_workers();
end $$;

create function cancel_pending_scheduling_rqs()
returns trigger
security definer
language plpgsql as $$
begin
update scheduling_request
set canceled = true
where status = 'pending'
and specification_id = new.specification_id;
return new;
end
$$;

create trigger cancel_pending_scheduling_rqs
before insert on scheduling_request
for each row
execute function cancel_pending_scheduling_rqs();

0 comments on commit a97b4d0

Please sign in to comment.