diff options
Diffstat (limited to 'sql/varnish.sql')
| -rw-r--r-- | sql/varnish.sql | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/sql/varnish.sql b/sql/varnish.sql index bfbdb743..10792088 100644 --- a/sql/varnish.sql +++ b/sql/varnish.sql @@ -2,20 +2,28 @@ BEGIN; -- -- Create a function to purge from varnish cache --- By default this adds the object to a pgq queue, +-- By default this adds the object to a local queue, -- but this function can be replaced with a void one -- when running a development version. -- +CREATE SCHEMA IF NOT EXISTS varnishqueue; +CREATE TABLE IF NOT EXISTS varnishqueue.queue (id bigserial primary key, mode char NOT NULL, consumerid int NOT NULL, expr text NOT NULL, added timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP, completed timestamptz NULL); +CREATE TABLE IF NOT EXISTS varnishqueue.consumers (consumerid serial PRIMARY KEY, consumer text NOT NULL); + +DROP FUNCTION IF EXISTS varnish_purge(url text); CREATE OR REPLACE FUNCTION varnish_purge(url text) -RETURNS bigint +RETURNS void AS $$ - SELECT pgq.insert_event('varnish', 'P', $1); + INSERT INTO varnishqueue.queue (mode, consumerid, expr) SELECT 'P', consumerid, $1 FROM varnishqueue.consumers; + NOTIFY varnishqueue; $$ LANGUAGE 'sql'; +DROP FUNCTION IF EXISTS varnish_purge_expr(expr text); CREATE OR REPLACE FUNCTION varnish_purge_expr(expr text) -RETURNS bigint +RETURNS void AS $$ - SELECT pgq.insert_event('varnish', 'X', $1); + INSERT INTO varnishqueue.queue (mode, consumerid, expr) SELECT 'X', consumerid, $1 FROM varnishqueue.consumers; + NOTIFY varnishqueue; $$ LANGUAGE 'sql'; -COMMIT;
\ No newline at end of file +COMMIT; |
