INSERT INTO pgagent.pga_jobclass (jclname)
    VALUES ('Cleanup Nonces');

INSERT INTO pgagent.pga_job (jobjclid, jobname, jobdesc, jobenabled, jobhostagent)
SELECT jcl.jclid, 'Cleanup Pending Nonces', 'Remove expired pending_nonces rows older than 5 minutes', true, ''
from pgagent.pga_jobclass jcl WHERE jclname='Cleanup Nonces';

INSERT INTO pgagent.pga_jobstep (jstjobid, jstname, jstdesc, jstenabled, jstkind, jstonerror, jstcode, jstdbname)
SELECT job.jobid, 'Perform Cleanup', 'Delete pending nonces', true, 's', 'f', $$DELETE FROM pending_nonces WHERE expires_at < NOW()$$, 'testdata'
FROM pgagent.pga_job job where jobname='Cleanup Pending Nonces';

INSERT INTO pgagent.pga_schedule (jscjobid, jscname, jscenabled, jscstart, jscminutes)
VALUES (
           (SELECT jobid
            from pgagent.pga_job
            where jobname = 'Cleanup Pending Nonces'),
           'Every 5 minutes',
           true,
           CURRENT_TIMESTAMP,  -- start anytime
           '{t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f,t,f,f,f,f}'  -- every 5th minute
       );