In this video we take a look at how to use Scheduler’s lightweight cron to publish and unpublish content on a more frequent basis, without affecting Drupal Core’s cron schedule.

As we’ve seen in previous videos, Scheduler performs its publishing and unpublishing of content when cron runs. Many modules hook into cron and perform a variety of actions on each cron run. This means that your site may see a slight performance hit each time cron does run. If we want to have fine-grained control over when content is published and unpublished using Scheduler, we might want to have cron run as often as every minute. Now, if you do have a lot of actions that get performed when cron runs, they may take more than a minute to complete, and then you run into issues where cron tries to run while it’s already running. To have our cake, and eat it too (have Drupal’s cron run every three hours, and have Scheduler check for content to publish and unpublish every minute) we can utilize Scheduler’s lightweight cron and set that to a frequency that’s more appropriate for our site.

The path to Scheduler’s lightweight cron is “/scheduler/cron”. This means that at any time, you can go to “example.com/scheduler/cron” and Scheduler will check for content that needs to be published and unpublished, without running Drupal’s system-wide cron.

Now that we know the path to the lightweight cron, we can create a crontab that will automatically access this page on a schedule that we define. This can be done a number of ways, and I’m going to show you how it is done via Plesk (because that’s what I use), but even if you’re using CPanel or another control panel, the process will still apply, and you can contact your hosting support team for instructions specific to your environment.

Before we actually set it up, let’s take a look at a documentation page. http://drupal.org/node/23714 has some great information on configuring cron. When you scroll down, there is a diagram that explains the crontab syntax. Basically, there are five parameters for setting the frequency of which the command should be executed, followed immediately by the actual command to execute. Another great resource is http://wikipedia.org/wiki/Cron. This page lists all of the available options for each parameter, so check that out for detailed information.

Scheduling tasks via Plesk

In order to schedule a new task via Plesk, we need to log in and find the “Scheduled Tasks” option.

  • Log in
  • Click the “Websites & Domains tab
  • Click “Show Advanced Operations”
  • Click “Scheduled Tasks”
  • Select your system user
  • Click “Schedule New Task”

Here we can start setting our parameters and give Plesk the command we’d like to execute. Since I want this to run every minute, I’m going to enter “*” for each parameter.

  • Minute: * (Every minute. This is the minute of the hour, so entering a “5” here would execute five minutes after the hour, not every five minutes.)
  • Hour: * (Every hour)
  • Day of the month: * (Every day of the month)
  • Month: * (Every month)
  • Day of the week: * (Every day of the week)
  • Command: /usr/bin/wget -O - -q "http://loc.scheduler.com:8082/scheduler/cron"
  • Click OK

Now that the task has been saved, it looks more like the examples we’ve seen on the help pages. This won’t actually work since my site is on my local machine, and not accessible remotely, but that’s all there is to it. Now, the lightweight scheduler cron will run every minute, and Drupal Core’s cron will run on its own, less frequent, schedule.