mirror of
https://git.asonix.dog/asonix/pict-rs
synced 2024-12-22 11:21:24 +00:00
Add notify function
This commit is contained in:
parent
46805f48b9
commit
b4bb111aed
1 changed files with 24 additions and 0 deletions
|
@ -41,6 +41,7 @@ CREATE TABLE hashes (
|
|||
motion_identifier TEXT,
|
||||
);
|
||||
|
||||
|
||||
CREATE TABLE variants (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
hash BYTEA REFERENCES hashes(hash) ON DELETE CASCADE,
|
||||
|
@ -48,6 +49,7 @@ CREATE TABLE variants (
|
|||
identifier TEXT NOT NULL
|
||||
);
|
||||
|
||||
|
||||
CREATE UNIQUE INDEX hash_variant_index ON variants (hash, variant);
|
||||
```
|
||||
|
||||
|
@ -133,6 +135,7 @@ methods:
|
|||
```sql
|
||||
CREATE TYPE job_status AS ENUM ('new', 'running');
|
||||
|
||||
|
||||
CREATE TABLE queue (
|
||||
id UUID PRIMARY KEY DEFAULT gen_random_uuid(),
|
||||
queue VARCHAR(30) NOT NULL,
|
||||
|
@ -142,6 +145,7 @@ CREATE TABLE queue (
|
|||
queue_time TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
|
||||
|
||||
CREATE INDEX queue_worker_id_index ON queue INCLUDE worker_id;
|
||||
CREATE INDEX queue_status_index ON queue INCLUDE status;
|
||||
```
|
||||
|
@ -150,6 +154,7 @@ claiming a job can be
|
|||
```sql
|
||||
DELETE FROM queue WHERE worker_id = '$WORKER_ID';
|
||||
|
||||
|
||||
UPDATE queue SET status = 'running', worker_id = '$WORKER_ID'
|
||||
WHERE id = (
|
||||
SELECT id
|
||||
|
@ -162,6 +167,25 @@ WHERE id = (
|
|||
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
|
||||
This is used for migrating from local storage to object storage. It keeps track of which identifiers
|
||||
|
|
Loading…
Reference in a new issue