Copy link to clipboard
Copied
Cron expression to schedule the task which will run at 11:45 pm at the end of the year
0 45 23 31 12 ?
This is what you need for it to work in the CF sched task mechanism. You may have found instead resources online suggesting it could be just this:
45 23 31 12 *
...such as at https://crontab.guru/#45_23_31_12_*. But if you use that for a CF task, you'd get:
CronExpression '45 23 31 12 *' is invalid.
The problem is in how the underlying Quartz open source library (which CF uses for scehduled tasks) expects its cron values to be specified.
Traditional crontab format
...Copy link to clipboard
Copied
0 45 23 31 12 ?
This is what you need for it to work in the CF sched task mechanism. You may have found instead resources online suggesting it could be just this:
45 23 31 12 *
...such as at https://crontab.guru/#45_23_31_12_*. But if you use that for a CF task, you'd get:
CronExpression '45 23 31 12 *' is invalid.
The problem is in how the underlying Quartz open source library (which CF uses for scehduled tasks) expects its cron values to be specified.
Traditional crontab format is:
minute, hour, day of month, month, day of week
The quartz cron pattern instead adds to that support for seconds (first field, required) and year (last field, optional):
second, minute, hour, day of month, month, day of week, year
Also, while the * for day of week (last value in my proposed expression) should work (according to the Quartz docs), I found that it did not, but the ? did. Technically, the ? should only be needed when some following field would be required but you wanted to imply "any" for the field with the "?". Logically, either should have worked. Oh well.
FWIW, CF2021 still uses only quartz 2.2.1, so I linked to the docs 2.2.2, which is close enough:
Also, here is a nifty online tool I found to help generate (or understand) a Quartz cron string. (I was reminded of it it after posting my answer, and I want to offer it here to help future readers.) It, too, shows using that ? in the 6th field...though it then shows using also the * for the 7th. As I noted above that's not needed, but I'll note here it does work (to switch the last "?" with "? *").
Let us know if that gets you going. I tested it (using a date and time of today) and it did work for me, in CF2021.
Copy link to clipboard
Copied
thanks.
Copy link to clipboard
Copied
Glad to help. Could you please mark my first response as the "answer", to help others.
BTW, I just tweaked it to add a link to an online generator of Quartz cron strings that you may find helpful.
Finally, given your seeming preference for extreme brevity :-), I sincerely think you may find you'd REALLY enjoy the CFML slack channel, where most conversations are in mere sentences. Not my cup of tea, obviously. 🙂
Copy link to clipboard
Copied
The Freeformatter tool was suggested at least once, previously, in a similar discussion in this forum.
(Just for general information.)
Copy link to clipboard
Copied
Yes, bkbk. I pointed it out there there in my comment on June 6 2021. But rather than point folks here to that comment (or to your mention of it a few days later), I opted to offer here the direct link to the tool here. That seemed far more appropriate.