Serge Bazanski | a9580a7 | 2023-01-12 14:44:35 +0100 | [diff] [blame] | 1 | CREATE TYPE work_history_event AS ENUM ( |
| 2 | 'Started', |
| 3 | 'Finished', |
| 4 | 'Failed', |
| 5 | 'Canceled' |
| 6 | ); |
| 7 | |
| 8 | -- Audit trail of work history for a given machine. |
| 9 | CREATE TABLE work_history( |
| 10 | -- The machine subject to this audit entry. As we want to allow keeping |
| 11 | -- information about deleted machines, this is not a foreign key. |
| 12 | machine_id UUID NOT NULL, |
| 13 | |
| 14 | -- TODO(q3k): session history? |
| 15 | |
| 16 | -- Process acting on this machine which caused an audit entry to be created. |
| 17 | process process NOT NULL, |
| 18 | -- Process lifecycle event (started, finished, etc) that caused this audit |
| 19 | -- entry to be created. |
| 20 | event work_history_event NOT NULL, |
| 21 | -- Time at which this entry was created. |
| 22 | timestamp TIMESTAMPTZ NOT NULL, |
| 23 | |
| 24 | -- Failure cause, only set when event == Failed. |
| 25 | failed_cause STRING |
| 26 | ); |
| 27 | |
| 28 | CREATE INDEX ON work_history (machine_id); |
| 29 | |
| 30 | -- Backoff entries are created by failed work items, and effectively act as |
| 31 | -- a Lockout-tagout entry for a given machine and a given process. |
| 32 | -- |
| 33 | -- Currently, there is no way to fully backoff an entire machine, just |
| 34 | -- individual processes from a given machine. |
| 35 | -- |
| 36 | -- Backoff entries are only valid as long as 'until' is before now(), after that |
| 37 | -- they are ignored by workflow queries. Insertion queries act as upserts, |
| 38 | -- and thus the backoff entries do not need to be garbage collected, as they do |
| 39 | -- not grow unbounded (maximumum one entry per process/machine). |
| 40 | CREATE TABLE work_backoff( |
| 41 | -- The machine affected by this backoff. |
| 42 | machine_id UUID NOT NULL REFERENCES machines(machine_id) ON DELETE CASCADE, |
| 43 | -- The process that this machine should not be subjected to. |
| 44 | process process NOT NULL, |
| 45 | -- Until when the backoff is enforced. |
| 46 | until TIMESTAMPTZ NOT NULL, |
| 47 | |
| 48 | -- Error reported by process/work when this backoff was inserted. |
| 49 | -- Human-readable. |
| 50 | cause STRING NOT NULL, |
| 51 | |
| 52 | UNIQUE(machine_id, process) |
| 53 | ); |