Reputation: 23
One of the extensions I have installed in Magento has a cron scheduled with the expression 0 0 4 1/1 * ? *
. From what I've gathered means it should run every day at 4am.
When the Magento cron runs I get an error report saying: Invalid cron expression: 0 0 4 1/1 * ? *
. I haven't been able to find any information on the valid format for Magento crons. Should they only have 5 fields?
Upvotes: 2
Views: 3159
Reputation: 197767
The cron expression in Magento 1 can have five or six columns (fields). Column separator is white-space.
If there are less than five or more than six columns, you'll get a Mage_Cron_Exception with the message "Invalid cron expression: <expression>" in which <expression> is replaced with the verbatim string value of the configuration option that is getting parsed. This is the exact exception message you have in your question.
This most generic Mage_Cron_Exception message is given if the fundamental white-space parsing into the right number of columns fails or if any of the columns can't be parsed as any of the following cron expressions:
*
- ALL match...,...
- multiple options (each one of the comma-separated must validate again)...\...
- modulus (two elements, second one must be numeric)...-...
- range (from - to) of numeric data, three-letter English abbreviations of month and weekday names are translated into their numeric counterpart (using "mon" for month will result in 1 (January), "sun" for month as 0 (undefined but not invalid) etc.).If on any of these (or in case of the multiple options, any of the sub-options) results in some parsing problem, the Mage_Cron_Exception with the message "Invalid cron expression" is suffixed with additional information like:
", expecting 'from-to' structure: <expression>"
", expecting 'match/modulus': <expression>"
", expecting numeric modulus: <expression>"
... and so on
Cron expression parsing is done in Mage_Cron_Model_Schedule::getCronExprArr()
and Mage_Cron_Model_Schedule::matchCronExpression()
.
0 0 4 1/1 * ? *
In your case the cron expression has a correct number of fields (six) but the value "?
" you have for the fifth column is not parsed in a Magento cron expression resulting in the generic message (as it's not identified as any of the field value formats).
The format is a subset of the CRON expression (as given per Wikipedia). The sixth field (year) can be set but is never taken into consideration.
Upvotes: 2
Reputation: 6199
By default Magento uses SimpleTrigger format (the one with 5 fields), however your cron here is in CronTrigger format.
I'm not an expert in cron but I think your cron is setting a daily schedule to run at 4 AM (check it out here); Just try to restyle it in the SimpleTrigger format which would be:
0 4 * * *
Upvotes: 0