Skip to content

Commit

Permalink
refactor: remove unused graphile_worker_timestamp table
Browse files Browse the repository at this point in the history
  • Loading branch information
dleard committed Jun 23, 2020
1 parent 0889854 commit 2d60b89
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 153 deletions.
16 changes: 0 additions & 16 deletions schema/deploy/policies/graphile_worker_timestamp_policies.sql

This file was deleted.

22 changes: 0 additions & 22 deletions schema/deploy/tables/graphile_worker_timestamp.sql

This file was deleted.

8 changes: 0 additions & 8 deletions schema/revert/policies/graphile_worker_timestamp_policies.sql

This file was deleted.

7 changes: 0 additions & 7 deletions schema/revert/tables/graphile_worker_timestamp.sql

This file was deleted.

1 change: 0 additions & 1 deletion schema/sqitch.plan
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,3 @@ trigger_functions/organisation_access_approved [trigger_functions/organisation_a
trigger_functions/run_graphile_worker_job [trigger_functions/run_graphile_worker_job@v1.0.0-rc.5 schema_ggircs_portal] 2020-06-20T00:11:19Z Kristen Cooke <kristen@button.is> # Adds more data to application status change and signed by certifier email jobs
tables/graphile_worker_timestamp [schema_ggircs_portal_private] 2020-06-19T20:30:46Z Dylan Leard <dylan@button.is> # Table tracks calls to graphile_worker.addjob()
database_functions/graphile_worker_job_definer [database_functions/graphile_worker_job_definer@v1.0.0-rc.5] 2020-06-22T16:36:16Z Dylan Leard <dylan@button.is> # change to graphile_worker_job_definer adds add_job() throttling
policies/graphile_worker_timestamp_policies [tables/graphile_worker_timestamp] 2020-06-22T18:21:46Z Dylan Leard <dylan@button.is> # Row level security policies for graphile_worker_timestamp table
Original file line number Diff line number Diff line change
Expand Up @@ -3,86 +3,12 @@ create extension if not exists pgtap;
reset client_min_messages;

begin;
select plan(6);
select plan(1);

select has_function(
'ggircs_portal_private', 'graphile_worker_job_definer',
'Function graphile_worker_job_definer should exist'
);

create or replace function ggircs_portal_private.graphile_worker_job_definer(task text, payload json)
returns void as $$
declare
calls_past_minute int;
defer_run_multiplier int;
begin

calls_past_minute := (select count(*) from ggircs_portal_private.graphile_worker_timestamp where called_at > (now() - interval '1 minute'));
defer_run_multiplier := (calls_past_minute/100);

-- Update the function for test purposes, so it can be run without attempting to call the graphile_worker schema.
-- perform graphile_worker.add_job(task, payload, run_at := now() + ((defer_run_multiplier) * INTERVAL '1 minute'));
insert into ggircs_portal_private.graphile_worker_timestamp(called_at) values (now() + ((defer_run_multiplier) * INTERVAL '1 minute'));

end;
$$ language plpgsql volatile security definer;

-- Test function adds a defined number of applications, which in turn calls graphile_worker_job_definer via a trigger
create or replace function add_apps(max int)
returns void as $$
begin
for i in 1..max loop
perform ggircs_portal.create_application_mutation_chain(1);
end loop;
end;
$$ language plpgsql;

select is_empty(
$$
select * from ggircs_portal_private.graphile_worker_timestamp;
$$,
'The graphile_worker_timestamp table is empty'
);

-- Make 201 calls to graphile_worker_job_definer
select add_apps(201);

select * from ggircs_portal_private.graphile_worker_timestamp;

select results_eq(
$$
select count(*) from ggircs_portal_private.graphile_worker_timestamp where called_at between now() - interval '1 minute' and now();
$$,
ARRAY['100'::bigint],
'There are 100 entries in graphile_worker_timestamp where the timestamp is between now and now() - 1 minute'
);

select results_eq(
$$
select count(*) from ggircs_portal_private.graphile_worker_timestamp where called_at between now() + interval '1 second' and now() + interval '1 minute';
$$,
ARRAY['100'::bigint],
'There are 100 entries in graphile_worker_timestamp where the timestamp is between now() and now() + 1 minute'
);

select results_eq(
$$
select count(*) from ggircs_portal_private.graphile_worker_timestamp where called_at between now() + interval '1 minute' + interval '1 second' and now() + interval '2 minutes';
$$,
ARRAY['1'::bigint],
'There is one entry in graphile_worker_timestamp where the timestamp is between now() + 1 minute and now() + 2 minutes'
);

-- Make another call to graphile_worker_job_definer
select add_apps(1);

select results_eq(
$$
select count(*) from ggircs_portal_private.graphile_worker_timestamp where called_at between now() + interval '1 minute' + interval '1 second' and now() + interval '2 minutes';
$$,
ARRAY['2'::bigint],
'There are two entries in graphile_worker_timestamp where the timestamp is between now() + 1 minute and now() + 2 minutes'
);

select finish();
rollback;
17 changes: 0 additions & 17 deletions schema/verify/policies/graphile_worker_timestamp_policies.sql

This file was deleted.

7 changes: 0 additions & 7 deletions schema/verify/tables/graphile_worker_timestamp.sql

This file was deleted.

0 comments on commit 2d60b89

Please sign in to comment.