Allow manual triggering by streamer of streamer-specific cronjobs
Implement cronjob system
Updated version:
CREATE TABLE cron (
id integer GENERATED ALWAYS AS IDENTITY,
name varchar NOT NULL, -- Application-recognizable name for the job
runinterval interval, -- Duration between runs
lastSuccess timestamptz -- Last successful run - only gets updated if run is successful
);
BEGIN; -- Transaction necessary for locking
SELECT * FROM cron
WHERE (lastSuccess + runInterval) < now() -- Next run should be before now
AND name = 'jobName' -- Application will iterate through jobs it knows about, specifying job name in query
FOR UPDATE SKIP LOCKED; -- Lock row, do not include rows currently locked
-- If no rows returned by select, either no pending jobs or all pending jobs are already being handled. Either way, nothing to do, so application subroutine should exit
COMMIT;
Changes from app saying "give me a job to do" to "does this job need done?". This way, the application will never get a job it doesn't know how to handle, and will guarantee all jobs that need to get run do so in one cron cycle.
Implement cronjob system
CREATE TABLE cron (
id integer GENERATED ALWAYS AS IDENTITY,
name varchar NOT NULL, -- Application-recognizable name for the job
runinterval interval, -- Duration between runs
lastSuccess timestamptz -- Last successful run - only gets updated if run is successful
);
BEGIN; -- Transaction necessary for locking
SELECT * FROM cron
WHERE (lastSuccess + runInterval) < now() -- Next run should be before now
FOR UPDATE SKIP LOCKED LIMIT 1; -- Lock one not-already-locked row
-- If no rows returned by select, either no pending jobs or all pending jobs are already being handled. Either way, nothing to do, so application subroutine should exit
COMMIT;
Implement cronjob system
Functions that need this:
- Bans
- Updating empty metadata
- Retrieving followers and subscribers