Project

General

Profile

Paste
Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / job_scheduler @ 082b75eb

Name Size Revision Age Author Comment
  modules 082b75eb over 6 years Assos Assos Weekly update of contrib modules
CHANGELOG.txt 1.01 KB f7a2490e over 10 years Assos Assos git mv htmltest drupal7
JobScheduler.inc 6.62 KB 082b75eb over 6 years Assos Assos Weekly update of contrib modules
JobSchedulerCronTab.inc 9.33 KB 082b75eb over 6 years Assos Assos Weekly update of contrib modules
LICENSE.txt 17.7 KB f7a2490e over 10 years Assos Assos git mv htmltest drupal7
README.txt 4.7 KB 082b75eb over 6 years Assos Assos Weekly update of contrib modules
job_scheduler.api.php 1.7 KB 082b75eb over 6 years Assos Assos Weekly update of contrib modules
job_scheduler.info 432 Bytes 082b75eb over 6 years Assos Assos Weekly update of contrib modules
job_scheduler.install 5.11 KB 082b75eb over 6 years Assos Assos Weekly update of contrib modules
job_scheduler.module 7.1 KB 082b75eb over 6 years Assos Assos Weekly update of contrib modules

Latest revisions

# Date Author Comment
082b75eb 02/15/2018 02:26 AM Assos Assos

Weekly update of contrib modules

f7a2490e 02/13/2014 03:56 PM Assos Assos

git mv htmltest drupal7

View revisions

README


CONTENTS OF THIS FILE

  • Introduction
  • Requirements
  • Installation
  • Configuration
  • Usage
    • Drupal Queue integration
    • Example
    • Hidden settings
  • Maintainers

INTRODUCTION

Simple API for scheduling tasks once at a predetermined time or periodically at
a fixed interval.

REQUIREMENTS

No special requirements

INSTALLATION

Install as you would normally install a contributed Drupal module. See:
https://drupal.org/documentation/install/modules-themes/modules-7 for further
information.

CONFIGURATION

No menu or modifiable settings.

USAGE

  • Declare scheduler.

function example_cron_job_scheduler_info() {
$schedulers - array();
$schedulers['example_unpublish'] - array(
'worker callback' -> 'example_unpublish_nodes',
);
return $schedulers;
}

  • Add a job.

$job - array(
'type' -> 'story',
'id' -> 12,
'period' -> 3600,
'periodic' -> TRUE,
);
JobScheduler::get('example_unpublish')->set($job);

  • Work off a job.

function example_unpublish_nodes($job) {
// Do stuff.
}

  • Remove a job.

$job - array(
'type' -> 'story',
'id' -> 12,
);
JobScheduler::get('example_unpublish')->remove($job);

Optionally jobs can declared together with a schedule in a:
hook_cron_job_scheduler_info().

function example_cron_job_scheduler_info() {
$schedulers - array();
$schedulers['example_unpublish'] - array(
'worker callback' -> 'example_unpublish_nodes',
'jobs' -> array(
array(
'type' -> 'story',
'id' -> 12,
'period' -> 3600,
'periodic' -> TRUE,
),
)
);
return $schedulers;
}

Jobs can have a 'crontab' instead of a period. Crontab syntax are Unix-like
formatted crontab lines.

Example of job with crontab.

This will create a job that will be triggered from monday to friday, from
january to july, every two hours:

function example_cron_job_scheduler_info() {
$schedulers - array();
$schedulers['example_unpublish'] - array(
'worker callback' -> 'example_unpublish_nodes',
'jobs' -> array(
array(
'type' -> 'story',
'id' -> 12,
'crontab' -> '0 */2 * january-july mon-fri',
'periodic' -> TRUE,
),
)
);
return $schedulers;
}

Read more about crontab syntax: http://linux.die.net/man/5/crontab

DRUPAL QUEUE INTEGRATION

Optionally, at the scheduled time Job Scheduler can queue a job for execution,
rather than executing the job directly. This is useful when many jobs need to
be executed or when the job's expected execution time is very long.

More information on Drupal Queue: http://api.drupal.org/api/group/queue/7

Instead of declaring a worker callback, declare a queue name.

function example_cron_job_scheduler_info() {
$schedulers - array();
$schedulers['example_unpublish'] - array(
'queue name' -> 'example_unpublish_queue',
);
return $schedulers;
}

This of course assumes that you have declared a queue. Notice how in this
pattern the queue callback contains the actual worker callback.

function example_cron_queue_info() {
$schedulers - array();
$schedulers['example_unpublish_queue'] - array(
'worker callback' -> 'example_unpublish_nodes',
);
return $schedulers;
}

Work off a job: when using a queue, Job Scheduler reserves a job for one hour
giving the queue time to work off a job before it reschedules it. This means
that the worker callback needs to reset the job's schedule flag in order to
allow renewed scheduling.

function example_unpublish_nodes($job) {
// Do stuff.
// Set the job again so that its reserved flag is reset.
JobScheduler::get('example_unpublish')->set($job);
}

EXAMPLE

See Feeds module.

HIDDEN SETTINGS

Hidden settings are variables that you can define by adding them to the $conf
array in your settings.php file.

Name: 'job_scheduler_class_' . $name
Default: 'JobScheduler'
Description: The class to use for managing a particular schedule.

MAINTAINERS

Current maintainers:

Also available in: Atom