• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

CF Adminstrator scheduled task to run at the last day of the year using CRON TIME expression

New Here ,
Feb 25, 2022 Feb 25, 2022

Copy link to clipboard

Copied

Cron expression to schedule the task which will run at 11:45 pm at the end of the year


Views

164

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Feb 25, 2022 Feb 25, 2022

 

 

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

...

Votes

Translate

Translate
Community Expert ,
Feb 25, 2022 Feb 25, 2022

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.


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 25, 2022 Feb 25, 2022

Copy link to clipboard

Copied

thanks. 

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 25, 2022 Feb 25, 2022

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. 🙂


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2022 Feb 26, 2022

Copy link to clipboard

Copied

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Feb 26, 2022 Feb 26, 2022

Copy link to clipboard

Copied

LATEST

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. 


/Charlie (troubleshooter, carehart.org)

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Resources
Documentation