jin
jin

Reputation: 71

Cron job on Magento doesn't work properly

I have a problem with Magento cron expression. It works fine with minutes:

    <crontab>
    <jobs>
        <namespace_module_cron>
            <schedule>
                <cron_expr>*/15 * * * *</cron_expr>
            </schedule>
            <run>
                <model>namespace_module/observer::myMethod</model>
            </run>
        </namespace_module_cron>
    </jobs>
</crontab>

But it doesn't work when I set hours:

<cron_expr>0 1 * * *</cron_expr>

or

<cron_expr>0 */1 * * *</cron_expr>

I tried different time settings in admin panel. For now there are:

P.S. Magento ver. 1.7.0.1

Update

I left every hour job (0 */1 * * *) for a day and it actually runs:

Upvotes: 3

Views: 8939

Answers (4)

Jarrod Juleff
Jarrod Juleff

Reputation: 85

I know this is old, but it may still be relevant as I encountered something similar. How often is your cron.sh scheduled to run on your server. If the scheduler is set to every 60 minutes and it runs on the hour (12pm, 1pm 2pm... etc) and your Scheduled ahead time is set to 20 minutes (default i think), and your magento cron expression is, for example, 30 * * * *, or every hour on the half hour, you job will never run. Your cron.sh will only set up magento cron jobs up to 20 minutes ahead, and so the 12:30 job will not get scheduled, but since magento's cron.sh is set to run on the hour, it will never get scheduled. I suspect your original problem is something similar, because adjusting the "scheduled ahead" time past the time the magento cron should be scheduled fix an issue like this. Just something to look out for as well.

Upvotes: 1

jin
jin

Reputation: 71

I've figured out what was wrong. It were settings (System/Configuration/System/Cron). When I set up "Schedule Ahead for" to 60 it started to work properly (every hour and every day schedules). For now schedule in database is appearing at 15:20 when I need to execute it 16:00.

Settings:

  • Generate Schedules Every: 15
  • Schedule Ahead for: 60
  • Missed if Not Run Within: 60
  • History Cleanup Every: 120
  • Success History Lifetime: 120
  • Failure History Lifetime: 3000

If you have the same problem, you should pay attention to first two settings: "Generate Schedules Every" and "Schedule Ahead for"

Upvotes: 4

mahesh kajale
mahesh kajale

Reputation: 530

I have defined the corn job like this. 03 16 * * *

when your cron.php runs at 16:02 o'clock then it will create only an entry about this cron job in database table cron_schedule and it will not run the cron job. To run this cron job i need to run cron.php twice, means after creating an entry in table you should run cron within 15 minitues, otherwise that entry is ignored. So to run the cron job, you should run the cron.php periodically.

my cron job run every day at 16:03 and i run cron.php every after 10 minute

Upvotes: 1

Jscti
Jscti

Reputation: 14440

For every hour at 0 minutes (00:00, 01:00; 02:00 etc), you must put :

<cron_expr>0 * * * *</cron_expr>

Upvotes: 1

Related Questions