You are here

README.txt in Job Scheduler 7.2

Same filename and directory in other branches
  1. 8.3 README.txt
  2. 8.2 README.txt
  3. 6 README.txt
  4. 7 README.txt
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:
 * Frank Febbraro (febbraro) - https://www.drupal.org/user/43670
 * Renato Gonçalves (RenatoG) - https://www.drupal.org/user/3326031
 * Alex Barth (alex_b) - https://www.drupal.org/user/53995
 * Chris Leppanen (twistor) - https://www.drupal.org/user/473738
 * Florian Weber (webflo) - https://www.drupal.org/user/254778
 * Gabe Sullice (gabesullice) - https://www.drupal.org/user/2287430
 * Jeff Miccolis (jmiccolis) - https://www.drupal.org/user/31731
 * Joachim Noreiko (joachim) - https://www.drupal.org/user/107701
 * makara - https://www.drupal.org/user/132402

File

README.txt
View source
  1. CONTENTS OF THIS FILE
  2. ---------------------
  3. * Introduction
  4. * Requirements
  5. * Installation
  6. * Configuration
  7. * Usage
  8. * Drupal Queue integration
  9. * Example
  10. * Hidden settings
  11. * Maintainers
  12. INTRODUCTION
  13. ------------
  14. Simple API for scheduling tasks once at a predetermined time or periodically at
  15. a fixed interval.
  16. REQUIREMENTS
  17. ------------
  18. No special requirements
  19. INSTALLATION
  20. ------------
  21. Install as you would normally install a contributed Drupal module. See:
  22. https://drupal.org/documentation/install/modules-themes/modules-7 for further
  23. information.
  24. CONFIGURATION
  25. -------------
  26. No menu or modifiable settings.
  27. USAGE
  28. -----
  29. * Declare scheduler.
  30. function example_cron_job_scheduler_info() {
  31. $schedulers - array();
  32. $schedulers['example_unpublish'] - array(
  33. 'worker callback' -> 'example_unpublish_nodes',
  34. );
  35. return $schedulers;
  36. }
  37. * Add a job.
  38. $job - array(
  39. 'type' -> 'story',
  40. 'id' -> 12,
  41. 'period' -> 3600,
  42. 'periodic' -> TRUE,
  43. );
  44. JobScheduler::get('example_unpublish')->set($job);
  45. * Work off a job.
  46. function example_unpublish_nodes($job) {
  47. // Do stuff.
  48. }
  49. * Remove a job.
  50. $job - array(
  51. 'type' -> 'story',
  52. 'id' -> 12,
  53. );
  54. JobScheduler::get('example_unpublish')->remove($job);
  55. Optionally jobs can declared together with a schedule in a:
  56. hook_cron_job_scheduler_info().
  57. function example_cron_job_scheduler_info() {
  58. $schedulers - array();
  59. $schedulers['example_unpublish'] - array(
  60. 'worker callback' -> 'example_unpublish_nodes',
  61. 'jobs' -> array(
  62. array(
  63. 'type' -> 'story',
  64. 'id' -> 12,
  65. 'period' -> 3600,
  66. 'periodic' -> TRUE,
  67. ),
  68. )
  69. );
  70. return $schedulers;
  71. }
  72. Jobs can have a 'crontab' instead of a period. Crontab syntax are Unix-like
  73. formatted crontab lines.
  74. Example of job with crontab.
  75. This will create a job that will be triggered from monday to friday, from
  76. january to july, every two hours:
  77. function example_cron_job_scheduler_info() {
  78. $schedulers - array();
  79. $schedulers['example_unpublish'] - array(
  80. 'worker callback' -> 'example_unpublish_nodes',
  81. 'jobs' -> array(
  82. array(
  83. 'type' -> 'story',
  84. 'id' -> 12,
  85. 'crontab' -> '0 */2 * january-july mon-fri',
  86. 'periodic' -> TRUE,
  87. ),
  88. )
  89. );
  90. return $schedulers;
  91. }
  92. Read more about crontab syntax: http://linux.die.net/man/5/crontab
  93. DRUPAL QUEUE INTEGRATION
  94. ------------------------
  95. Optionally, at the scheduled time Job Scheduler can queue a job for execution,
  96. rather than executing the job directly. This is useful when many jobs need to
  97. be executed or when the job's expected execution time is very long.
  98. More information on Drupal Queue: http://api.drupal.org/api/group/queue/7
  99. Instead of declaring a worker callback, declare a queue name.
  100. function example_cron_job_scheduler_info() {
  101. $schedulers - array();
  102. $schedulers['example_unpublish'] - array(
  103. 'queue name' -> 'example_unpublish_queue',
  104. );
  105. return $schedulers;
  106. }
  107. This of course assumes that you have declared a queue. Notice how in this
  108. pattern the queue callback contains the actual worker callback.
  109. function example_cron_queue_info() {
  110. $schedulers - array();
  111. $schedulers['example_unpublish_queue'] - array(
  112. 'worker callback' -> 'example_unpublish_nodes',
  113. );
  114. return $schedulers;
  115. }
  116. Work off a job: when using a queue, Job Scheduler reserves a job for one hour
  117. giving the queue time to work off a job before it reschedules it. This means
  118. that the worker callback needs to reset the job's schedule flag in order to
  119. allow renewed scheduling.
  120. function example_unpublish_nodes($job) {
  121. // Do stuff.
  122. // Set the job again so that its reserved flag is reset.
  123. JobScheduler::get('example_unpublish')->set($job);
  124. }
  125. EXAMPLE
  126. -------
  127. See Feeds module.
  128. HIDDEN SETTINGS
  129. ---------------
  130. Hidden settings are variables that you can define by adding them to the $conf
  131. array in your settings.php file.
  132. Name: 'job_scheduler_class_' . $name
  133. Default: 'JobScheduler'
  134. Description: The class to use for managing a particular schedule.
  135. MAINTAINERS
  136. -----------
  137. Current maintainers:
  138. * Frank Febbraro (febbraro) - https://www.drupal.org/user/43670
  139. * Renato Gonçalves (RenatoG) - https://www.drupal.org/user/3326031
  140. * Alex Barth (alex_b) - https://www.drupal.org/user/53995
  141. * Chris Leppanen (twistor) - https://www.drupal.org/user/473738
  142. * Florian Weber (webflo) - https://www.drupal.org/user/254778
  143. * Gabe Sullice (gabesullice) - https://www.drupal.org/user/2287430
  144. * Jeff Miccolis (jmiccolis) - https://www.drupal.org/user/31731
  145. * Joachim Noreiko (joachim) - https://www.drupal.org/user/107701
  146. * makara - https://www.drupal.org/user/132402