Add cron.dom_dow_and_logic parameter to control days logic#421
Add cron.dom_dow_and_logic parameter to control days logic#421vdjakovic wants to merge 1 commit intocitusdata:mainfrom
Conversation
Currently, pg_cron follows the Vixie cron standard where a configured day-of-month (DOM) and day-of-week (DOW) are combined with OR logic. This makes it impossible to schedule jobs that must satisfy both a day-of-month and a day-of-week configuration. A common use case is scheduling a job to run on the "first Sunday of every month." With the default OR logic, an expression like '0 5 1-7 * 0' would run at 5:00 AM on days 1 through 7 of the month AND on every Sunday of the month. Which does not have much practical value. This commit introduces a new parameter, `cron.dom_dow_and_logic`, to give users control over this behavior. When set to `true`, pg_cron will use AND logic when both DOM and DOW fields are configured. With this feature enabled, the expression '0 5 1-7 * 0' runs only on the day that is both within the first 7 days of the month AND is a Sunday.
sfc-gh-mslot
left a comment
There was a problem hiding this comment.
I think first Sunday of the month is a reasonable request. This patch is very small, so that's good. There probably isn't a very simple and intuitive syntax change we can make.
The general recommendation would be for the query/function being invoked to check what day it is, but that is a bit annoying.
| check_timezone, NULL, NULL); | ||
|
|
||
| DefineCustomBoolVariable( | ||
| "cron.dom_dow_and_logic", |
There was a problem hiding this comment.
Struggling a bit with this name, maybe cron.match_dom_and_dow communicates the intent slightly more rather than referring to the implementation logic. Any thoughts?
There was a problem hiding this comment.
Agreed, it becomes even more complicated with vacuum because it can't be run inside transaction/function, having is fixed here sounds most logical and future proof, cron.match_dom_and_dow is better name.
Is this one good for you?
DefineCustomBoolVariable(
"cron.match_dom_and_dow",
gettext_noop("Requires a day to match both the day-of-month and day-of-week fields."),
NULL,
&CronDomDowAndLogic,
false,
Currently, pg_cron follows the Vixie cron standard where a configured day-of-month (DOM) and day-of-week (DOW) are combined with OR logic. This makes it impossible to schedule jobs that must satisfy both a day-of-month and a day-of-week configuration.
A common use case is scheduling a job to run on the "first Sunday of every month." With the default OR logic, an expression like '0 5 1-7 * 0' would run at 5:00 AM on days 1 through 7 of the month AND on every Sunday of the month. Which does not have much practical value.
This commit introduces a new parameter,
cron.dom_dow_and_logic, to give users control over this behavior. When set totrue, pg_cron will use AND logic when both DOM and DOW fields are configured.With this feature enabled, the expression '0 5 1-7 * 0' runs only on the day that is both within the first 7 days of the month AND is a Sunday.