You are here

README.txt in Job Scheduler 7

Same filename and directory in other branches
  1. 8.3 README.txt
  2. 8.2 README.txt
  3. 6 README.txt
  4. 7.2 README.txt
Job Scheduler
=============

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);


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.

  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.

File

README.txt
View source
  1. Job Scheduler
  2. =============
  3. Simple API for scheduling tasks once at a predetermined time or periodically at
  4. a fixed interval.
  5. Usage
  6. =====
  7. Declare scheduler.
  8. function example_cron_job_scheduler_info() {
  9. $schedulers = array();
  10. $schedulers['example_unpublish'] = array(
  11. 'worker callback' => 'example_unpublish_nodes',
  12. );
  13. return $schedulers;
  14. }
  15. Add a job.
  16. $job = array(
  17. 'type' => 'story',
  18. 'id' => 12,
  19. 'period' => 3600,
  20. 'periodic' => TRUE,
  21. );
  22. JobScheduler::get('example_unpublish')->set($job);
  23. Work off a job.
  24. function example_unpublish_nodes($job) {
  25. // Do stuff.
  26. }
  27. Remove a job.
  28. $job = array(
  29. 'type' => 'story',
  30. 'id' => 12,
  31. );
  32. JobScheduler::get('example_unpublish')->remove($job);
  33. Drupal Queue integration
  34. ========================
  35. Optionally, at the scheduled time Job Scheduler can queue a job for execution,
  36. rather than executing the job directly. This is useful when many jobs need to
  37. be executed or when the job's expected execution time is very long.
  38. More information on Drupal Queue: http://api.drupal.org/api/group/queue/7
  39. Instead of declaring a worker callback, declare a queue.
  40. function example_cron_job_scheduler_info() {
  41. $schedulers = array();
  42. $schedulers['example_unpublish'] = array(
  43. 'queue name' => 'example_unpublish_queue',
  44. );
  45. return $schedulers;
  46. }
  47. This of course assumes that you have declared a queue. Notice how in this
  48. pattern the queue callback contains the actual worker callback.
  49. function example_cron_queue_info() {
  50. $schedulers = array();
  51. $schedulers['example_unpublish_queue'] = array(
  52. 'worker callback' => 'example_unpublish_nodes',
  53. );
  54. return $schedulers;
  55. }
  56. Work off a job: when using a queue, Job Scheduler reserves a job for one hour
  57. giving the queue time to work off a job before it reschedules it. This means
  58. that the worker callback needs to reset the job's schedule flag in order to
  59. allow renewed scheduling.
  60. function example_unpublish_nodes($job) {
  61. // Do stuff.
  62. // Set the job again so that its reserved flag is reset.
  63. JobScheduler::get('example_unpublish')->set($job);
  64. }
  65. Example
  66. =======
  67. See Feeds module.
  68. Hidden settings
  69. ===============
  70. Hidden settings are variables that you can define by adding them to the $conf
  71. array in your settings.php file.
  72. Name: 'job_scheduler_class_' . $name
  73. Default: 'JobScheduler'
  74. Description: The class to use for managing a particular schedule.