Introduce cron_shutdown function for stopping the main background worker#381
Introduce cron_shutdown function for stopping the main background worker#381serpent7776 wants to merge 1 commit intocitusdata:mainfrom
Conversation
|
@microsoft-github-policy-service agree |
marcoslot
left a comment
There was a problem hiding this comment.
In principle this makes sense, but would be good if there's also a corresponding start-up function.
pg_cron--1.5--1.6.sql
Outdated
| @@ -1 +1,7 @@ | |||
| /* no SQL changes in 1.6 */ | |||
| DROP FUNCTION IF EXISTS cron.shutdown(); | |||
| CREATE FUNCTION cron.shutdown() | |||
There was a problem hiding this comment.
this would require a new SQL script (1.7), otherwise existing 1.6 users will never get the function.
pg_cron--1.5--1.6.sql
Outdated
| LANGUAGE C STRICT | ||
| AS 'MODULE_PATHNAME', $$cron_shutdown$$; | ||
| COMMENT ON FUNCTION cron.shutdown() | ||
| IS 'shutdown pg_cron'; |
There was a problem hiding this comment.
should also revoke execute from public, to ensure only superuser can call this (or grant privileges)
|
|
||
| LWLockAcquire(scheduler_shared_data->lock, LW_EXCLUSIVE); | ||
| pid = scheduler_shared_data->scheduler_pid; | ||
| scheduler_shared_data->scheduler_pid = 0; |
There was a problem hiding this comment.
the code style should be adapted to the rest of the project
(except the Vixie cron logic in entry.c/misc.c)
There was a problem hiding this comment.
I changed the style. Let me know if it's OK now.
|
For what need such function, if I can simply stop launch jobs by cron.launch_active_jobs = 'off' |
|
Setting |
Normally the main background worker used to start tasks cannot be stopped, because it always auto restarts. `cron_shutdown` function can be used to stop the background worker. `cron_startup` can be then used to start the scheduler again.
3007139 to
b5025bf
Compare
|
I updated the code. |
Normally the main background worker used to start tasks cannot be stopped, because it always auto restarts.
This change introduces SQL function
cron_shutdownthat can be used to stop the background worker.It works by creating a shared memory that holds pid of the main background worker and bool flag specifying whether to restart the worker. By default, this keeps the current behaviour of automatically restarting the worker whenever it's killed. In situations when the user actually wants the main worker to be killed, It gives a way to do it.
This currently doesn't stop any other worker started by the scheduler.
The change that introduced auto-restarts is #286
Fixes #352