Pages

Friday, August 28, 2009

SugarCRM Scheduler Explained

The SugarCRM scheduler functionality seems to be a source of confusion for some users. Hopefully this article will help add some clarity to its intended use and mechanics. To begin with, lets examine how the process works as a whole. First, a schedule or time table is defined by an admin level user via the Admin Control Panel. Each entry within the schedule includes not only the parameters for when things should run, but also which task should be performed. Some of the possible tasks are:

Prune database

Send campaign e-mails

Check inbound e-mail

However, in order for any of the tasks to occur, one must process the schedule. The processing is performed outside of Sugar and can be invoked on an ad-hoc basis or periodically via an external tool such as cron (Linux) or scheduler (Windows).

Instructions on which command to use to process the schedule are normally found in the scheduler page. Below is an example:

cd C:\xampp\xampp\htdocs\sugarce52 php.exe -f cron.php

Thus, it is necessary to do at least two things in order to get the scheduler to work. So far, so good.

Confusion usually starts to creep in when one realizes that cron and Windows scheduler also have a time table. The time table for both of those indicate the frequency in which the defined task is performed.

For example, one could configure Windows scheduler or cron to execute the command required by SugarCRM every hour, every day of the week.

NOTE: The rate at which the command is executed via cron or Windows scheduler is only indirectly associated with the time table defined by the admin user within SugarCRM.

Below is an example that illustrates the point:

SugarCRM scheduler is configured to send e-mail campaign messages at midnight, every day of the week.

cron is then configured to run the required execution command at 10 PM, every day of the week.

Despite cron executing its part correctly, Sugar will not perform any actions.

The reason: when cron runs the execution command at 10 PM, the process will examine the time table defined in SugarCRM in order to determine whether or not something should happen.

Because the Sugar defined schedule is configured to perform its task at 12:00 AM, the process ignores it, since it is not midnight at the time it is examined.

To address this situation, one must either adjust the time at which Sugar is scheduled to perform its task. Alternatively, one can choose to reconfigure the cron schedule to run every hour, at midnight or a few minutes thereafter.

The key to understanding this functionality is comprehending that SugarCRM merely creates the time table, but doesn't actually do anything at the specified times. Utilities such as cron or Windows scheduler are responsible for the latter.