* Adds job repo * Adds scheduler * Adds plugin table which is a place holder for future expansion of the scheduler. Currently all jobs that are created are linked to the pi_system plugin which are jobs that are held in a local registeredJobs map populated at controller startup.
89 lines
1.3 KiB
Go
89 lines
1.3 KiB
Go
package job
|
|
|
|
const runJobsQuery = `
|
|
insert into job_run (
|
|
job_plugin_id, job_name, server_id
|
|
)
|
|
select
|
|
job_plugin_id, job_name, ?
|
|
from job_jobs_to_run
|
|
order by next_scheduled_run asc
|
|
limit ?
|
|
returning *;
|
|
`
|
|
|
|
const createJobQuery = `
|
|
insert into job (
|
|
plugin_id, -- $1
|
|
name, -- $2
|
|
description, -- $3
|
|
next_scheduled_run -- $4
|
|
) values (
|
|
$1, -- plugin_id
|
|
$2, -- name
|
|
$3, -- description
|
|
wt_add_seconds_to_now($4) -- next_scheduled_run
|
|
)
|
|
returning *;
|
|
`
|
|
|
|
const setNextScheduledRunQuery = `
|
|
update
|
|
job
|
|
set
|
|
next_scheduled_run = wt_add_seconds_to_now(?)
|
|
where
|
|
plugin_id = ?
|
|
and name = ?
|
|
returning *;
|
|
`
|
|
|
|
const updateProgressQuery = `
|
|
update
|
|
job_run
|
|
set
|
|
completed_count = ?,
|
|
total_count = ?
|
|
where
|
|
private_id = ?
|
|
and status = 'running'
|
|
returning *;
|
|
`
|
|
|
|
const completeRunQuery = `
|
|
update
|
|
job_run
|
|
set
|
|
status = 'completed',
|
|
end_time = current_timestamp
|
|
where
|
|
private_id = ?
|
|
and status = 'running'
|
|
returning *;
|
|
`
|
|
|
|
const failRunQuery = `
|
|
update
|
|
job_run
|
|
set
|
|
status = 'failed',
|
|
end_time = current_timestamp
|
|
where
|
|
private_id = ?
|
|
and status = 'running'
|
|
returning *;
|
|
`
|
|
|
|
const interruptRunsQuery = `
|
|
update
|
|
job_run
|
|
set
|
|
status = 'interrupted',
|
|
end_time = current_timestamp
|
|
where
|
|
update_time <= wt_add_seconds_to_now(?)
|
|
and status = 'running'
|
|
%s
|
|
returning *;
|
|
`
|