Add notify function

This commit is contained in:
asonix 2023-07-24 19:38:12 -05:00
parent 46805f48b9
commit b4bb111aed

View file

@ -41,6 +41,7 @@ CREATE TABLE hashes (
motion_identifier TEXT, motion_identifier TEXT,
); );
CREATE TABLE variants ( CREATE TABLE variants (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(), id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
hash BYTEA REFERENCES hashes(hash) ON DELETE CASCADE, hash BYTEA REFERENCES hashes(hash) ON DELETE CASCADE,
@ -48,6 +49,7 @@ CREATE TABLE variants (
identifier TEXT NOT NULL identifier TEXT NOT NULL
); );
CREATE UNIQUE INDEX hash_variant_index ON variants (hash, variant); CREATE UNIQUE INDEX hash_variant_index ON variants (hash, variant);
``` ```
@ -133,6 +135,7 @@ methods:
```sql ```sql
CREATE TYPE job_status AS ENUM ('new', 'running'); CREATE TYPE job_status AS ENUM ('new', 'running');
CREATE TABLE queue ( CREATE TABLE queue (
id UUID PRIMARY KEY DEFAULT gen_random_uuid(), id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
queue VARCHAR(30) NOT NULL, queue VARCHAR(30) NOT NULL,
@ -142,6 +145,7 @@ CREATE TABLE queue (
queue_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP queue_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
); );
CREATE INDEX queue_worker_id_index ON queue INCLUDE worker_id; CREATE INDEX queue_worker_id_index ON queue INCLUDE worker_id;
CREATE INDEX queue_status_index ON queue INCLUDE status; CREATE INDEX queue_status_index ON queue INCLUDE status;
``` ```
@ -150,6 +154,7 @@ claiming a job can be
```sql ```sql
DELETE FROM queue WHERE worker_id = '$WORKER_ID'; DELETE FROM queue WHERE worker_id = '$WORKER_ID';
UPDATE queue SET status = 'running', worker_id = '$WORKER_ID' UPDATE queue SET status = 'running', worker_id = '$WORKER_ID'
WHERE id = ( WHERE id = (
SELECT id SELECT id
@ -162,6 +167,25 @@ WHERE id = (
returning *; returning *;
``` ```
notifying pict-rs of a ready job could be
```sql
CREATE OR REPLACE FUNCTION queue_status_notify()
RETURNS trigger AS
$$
BEGIN
PERFORM pg_notify('queue_status_channel', NEW.id::text);
RETURN NEW;
END;
$$ LANGUAGE plpgsql;
CREATE TRIGGER queue_status
AFTER INSERT OR UPDATE OF status
ON queue
FOR EACH ROW
EXECUTE PROCEDURE queue_status_notify();
```
### MigrationRepo ### MigrationRepo
This is used for migrating from local storage to object storage. It keeps track of which identifiers This is used for migrating from local storage to object storage. It keeps track of which identifiers