Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce cron_shutdown function for stopping the main background worker #381

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

serpent7776
Copy link

Normally the main background worker used to start tasks cannot be stopped, because it always auto restarts.

This change introduces SQL function cron_shutdown that 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

Normally the main background worker ued to start tasks cannot be
stopped, because it always auto restarts.
This SQL function can be used to stop the background worker.
@serpent7776
Copy link
Author

@microsoft-github-policy-service agree

Copy link
Collaborator

@marcoslot marcoslot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle this makes sense, but would be good if there's also a corresponding start-up function.

@@ -1 +1,7 @@
/* no SQL changes in 1.6 */
DROP FUNCTION IF EXISTS cron.shutdown();
CREATE FUNCTION cron.shutdown()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this would require a new SQL script (1.7), otherwise existing 1.6 users will never get the function.

LANGUAGE C STRICT
AS 'MODULE_PATHNAME', $$cron_shutdown$$;
COMMENT ON FUNCTION cron.shutdown()
IS 'shutdown pg_cron';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the code style should be adapted to the rest of the project

(except the Vixie cron logic in entry.c/misc.c)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unable to stop pg_cron scheduler
2 participants