About

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

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

HOTLINES

Phone : +84-(0)24-37683191
                     +84-(0)912439787

Fax : +84-(0)24-37683058
Email : cuchhvn@vinamarine.gov.vn

LINKS

ACCESS ANALYTICS

    • Total visits: 24329990
    • Online: 36