Files
threshold/internal/host/plugin/query.go
T
Jeff Mitchell 30e9f944a2 Add sync interval to host sets (#1680)
This adds a parameter to host sets allowing the sync interval to be
user-specified on a per-host-set basis. A value of -1 disables syncing;
a value of null uses the current default.
2021-11-11 11:28:08 -05:00

47 lines
1.1 KiB
Go

package plugin
const (
upsertHostCatalogSecretQuery = `
insert into host_plugin_catalog_secret
(catalog_id, secret, key_id)
values
(@catalog_id, @secret, @key_id)
on conflict (catalog_id) do update
set secret = excluded.secret,
key_id = excluded.key_id
returning *;
`
deleteHostCatalogSecretQuery = `
delete from host_plugin_catalog_secret
where catalog_id = @catalog_id;
`
setSyncNextRunInQuery = `
select
need_sync as sync_now,
sync_interval_seconds,
case
when sync_interval_seconds is null
then
extract(epoch from (least(now(), last_sync_time) + ?) - now())::int
when sync_interval_seconds > 0
then
extract(epoch from (least(now(), last_sync_time)) - now())::int + sync_interval_seconds
else
0
end resync_in
from host_plugin_set
order by need_sync desc, last_sync_time desc
limit 1;
`
setSyncJobQuery = `
need_sync
or
sync_interval_seconds is null and last_sync_time <= wt_add_seconds_to_now(?)
or
sync_interval_seconds > 0 and wt_add_seconds(sync_interval_seconds, last_sync_time) <= current_timestamp
`
)