Files
threshold/internal/scheduler/job/query.go
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

117 lines
1.9 KiB
Go
Raw Normal View History

2023-02-02 17:15:17 -08:00
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: BUSL-1.1
2021-05-06 14:54:10 -07:00
package job
const runJobsQuery = `
insert into job_run (
job_plugin_id, job_name, controller_id
2021-05-06 14:54:10 -07:00
)
select
j.plugin_id, j."name", ?
from job j
where next_scheduled_run <= current_timestamp
2021-05-06 14:54:10 -07:00
order by next_scheduled_run asc
on conflict
(job_plugin_id, job_name)
where status = 'running'
do nothing
2021-05-06 14:54:10 -07:00
returning *;
`
const upsertJobQuery = `
2021-05-06 14:54:10 -07:00
insert into job (
plugin_id,
name,
description,
next_scheduled_run
2021-05-06 14:54:10 -07:00
) values (
@plugin_id, -- plugin_id
@name, -- name
@description, -- description
wt_add_seconds_to_now(@next_scheduled_run) -- next_scheduled_run
2021-05-06 14:54:10 -07:00
)
on conflict on constraint
job_pkey
do update set
description = @description
2021-05-06 14:54:10 -07:00
returning *;
`
2021-06-11 11:36:14 -07:00
const setNextScheduledRunIfSoonerQuery = `
update
job
set
next_scheduled_run = least(wt_add_seconds_to_now(?), next_scheduled_run)
where
plugin_id = ?
and name = ?
returning *;
`
2021-05-06 14:54:10 -07:00
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 = ?,
2024-09-24 09:27:24 -04:00
total_count = ?,
retries_count = ?
2021-05-06 14:54:10 -07:00
where
private_id = ?
and status = 'running'
returning *;
`
const completeRunQuery = `
delete from job_run
2021-05-06 14:54:10 -07:00
where
private_id = ?
and status = 'running'
returning *;
`
const failRunQuery = `
update
job_run
set
completed_count = ?,
total_count = ?,
2024-09-24 09:27:24 -04:00
retries_count = ?,
status = 'failed',
end_time = current_timestamp
2021-05-06 14:54:10 -07:00
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 = ?
`