* Remove the server_id from session table, change it to worker_id on session_connection This is step 1 in updating the worker table. The worker is becoming a public resource so it must have a public id. We drop the server_id column on the session_connection table and add the worker_id column so we can use the wt_public_key type. Since db migrations are applied while the controller is offline, it should be safe to assume all session connections are not in a running state, thus allowing us to null out all the worker ids in the session_connection table. For now we don't have very good enforcement of the wt_public_id contraints, since the id is currently defined in the worker config, but this will soon change and the worker's id will be generated by the controller. * Updating server_id references to controller_id. * Adding worker tag db writing test. * Move the server table back to the top. * Update comment for the worker object. * Update comment for the worker table. * Update the newWorkerId call to take a context and fix its error. * Correct comment for the wt_network_address domain.
119 lines
1.9 KiB
Go
119 lines
1.9 KiB
Go
package job
|
|
|
|
const runJobsQuery = `
|
|
insert into job_run (
|
|
job_plugin_id, job_name, controller_id
|
|
)
|
|
select
|
|
job_plugin_id, job_name, ?
|
|
from job_jobs_to_run
|
|
order by next_scheduled_run asc
|
|
limit ?
|
|
on conflict
|
|
(job_plugin_id, job_name)
|
|
where status = 'running'
|
|
do nothing
|
|
returning *;
|
|
`
|
|
|
|
const upsertJobQuery = `
|
|
insert into job (
|
|
plugin_id,
|
|
name,
|
|
description,
|
|
next_scheduled_run
|
|
) values (
|
|
@plugin_id, -- plugin_id
|
|
@name, -- name
|
|
@description, -- description
|
|
wt_add_seconds_to_now(@next_scheduled_run) -- next_scheduled_run
|
|
)
|
|
on conflict on constraint
|
|
job_pkey
|
|
do update set
|
|
description = @description
|
|
returning *;
|
|
`
|
|
|
|
const setNextScheduledRunIfSoonerQuery = `
|
|
update
|
|
job
|
|
set
|
|
next_scheduled_run = least(wt_add_seconds_to_now(?), next_scheduled_run)
|
|
where
|
|
plugin_id = ?
|
|
and name = ?
|
|
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
|
|
completed_count = ?,
|
|
total_count = ?,
|
|
status = 'completed',
|
|
end_time = current_timestamp
|
|
where
|
|
private_id = ?
|
|
and status = 'running'
|
|
returning *;
|
|
`
|
|
|
|
const failRunQuery = `
|
|
update
|
|
job_run
|
|
set
|
|
completed_count = ?,
|
|
total_count = ?,
|
|
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 *;
|
|
`
|
|
|
|
const deleteJobByName = `
|
|
delete
|
|
from job
|
|
where
|
|
name = ?
|
|
`
|