-
Notifications
You must be signed in to change notification settings - Fork 4
feat: enhance refresh job scheduling with improved privilege handling… #551
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -234,22 +234,37 @@ def _create_refresh_function() -> str: | |||||||||||||||||||||||||||||
| def _schedule_refresh_job() -> str: | ||||||||||||||||||||||||||||||
| return f""" | ||||||||||||||||||||||||||||||
| DO $do$ | ||||||||||||||||||||||||||||||
| DECLARE | ||||||||||||||||||||||||||||||
| existing_job_id bigint; | ||||||||||||||||||||||||||||||
| BEGIN | ||||||||||||||||||||||||||||||
| SELECT jobid INTO existing_job_id | ||||||||||||||||||||||||||||||
| FROM cron.job | ||||||||||||||||||||||||||||||
| WHERE jobname = '{REFRESH_JOB_NAME}'; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| IF existing_job_id IS NOT NULL THEN | ||||||||||||||||||||||||||||||
| PERFORM cron.unschedule(existing_job_id); | ||||||||||||||||||||||||||||||
| END IF; | ||||||||||||||||||||||||||||||
| BEGIN | ||||||||||||||||||||||||||||||
| -- Avoid direct SELECT on cron.job because managed Postgres | ||||||||||||||||||||||||||||||
| -- environments may deny access to the cron schema table. | ||||||||||||||||||||||||||||||
| PERFORM cron.unschedule('{REFRESH_JOB_NAME}'); | ||||||||||||||||||||||||||||||
| EXCEPTION | ||||||||||||||||||||||||||||||
| WHEN undefined_function THEN | ||||||||||||||||||||||||||||||
| NULL; | ||||||||||||||||||||||||||||||
| WHEN invalid_parameter_value THEN | ||||||||||||||||||||||||||||||
| NULL; | ||||||||||||||||||||||||||||||
| WHEN internal_error THEN | ||||||||||||||||||||||||||||||
| -- Some pg_cron builds raise internal_error when the named | ||||||||||||||||||||||||||||||
| -- job does not exist. Treat this as already-unscheduled. | ||||||||||||||||||||||||||||||
| NULL; | ||||||||||||||||||||||||||||||
| WHEN insufficient_privilege THEN | ||||||||||||||||||||||||||||||
| RAISE NOTICE | ||||||||||||||||||||||||||||||
| 'Skipping pg_cron unschedule for % due to insufficient privileges.', | ||||||||||||||||||||||||||||||
| '{REFRESH_JOB_NAME}'; | ||||||||||||||||||||||||||||||
| RETURN; | ||||||||||||||||||||||||||||||
| END; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| PERFORM cron.schedule( | ||||||||||||||||||||||||||||||
|
Comment on lines
+238
to
258
|
||||||||||||||||||||||||||||||
| '{REFRESH_JOB_NAME}', | ||||||||||||||||||||||||||||||
| '{REFRESH_SCHEDULE}', | ||||||||||||||||||||||||||||||
| $cmd$SELECT public.{REFRESH_FUNCTION_NAME}();$cmd$ | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
| EXCEPTION | ||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||
| EXCEPTION | |
| EXCEPTION | |
| WHEN undefined_function THEN | |
| RAISE NOTICE | |
| 'Skipping pg_cron schedule for % because cron functions are not available.', | |
| '{REFRESH_JOB_NAME}'; | |
| WHEN invalid_parameter_value THEN | |
| RAISE NOTICE | |
| 'Skipping pg_cron schedule for % due to invalid parameter value.', | |
| '{REFRESH_JOB_NAME}'; | |
| WHEN internal_error THEN | |
| RAISE NOTICE | |
| 'Skipping pg_cron schedule for % due to internal pg_cron error.', | |
| '{REFRESH_JOB_NAME}'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Abort downgrade when pg_cron unschedule is unauthorized
Swallowing insufficient_privilege in the downgrade unschedule block allows the migration to continue and later drop public.refresh_pygeoapi_materialized_views(), even when the cron job could not be removed. In environments where the job is owned by a different role, this leaves the job active and it will keep firing a command that now points to a dropped function, causing recurring pg_cron execution errors after downgrade; previously this path failed fast instead of committing a broken partial teardown.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The PR description is still the template (Why/How/Notes bullets aren’t filled in). Please update the description to summarize the motivation and approach so reviewers/operators can understand the intended behavior changes around pg_cron privilege/error handling.