Project

General

Profile

Paste
Download (4.7 KB) Statistics
| Branch: | Revision:

root / drupal7 / sites / all / modules / job_scheduler / README.txt @ 082b75eb

1
CONTENTS OF THIS FILE
2
---------------------
3
   
4
 * Introduction
5
 * Requirements
6
 * Installation
7
 * Configuration
8
 * Usage
9
  * Drupal Queue integration
10
  * Example
11
  * Hidden settings
12
 * Maintainers
13

    
14

    
15
INTRODUCTION
16
------------
17

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

    
21

    
22
REQUIREMENTS
23
------------
24

    
25
No special requirements
26

    
27

    
28
INSTALLATION
29
------------
30

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

    
35

    
36
CONFIGURATION
37
-------------
38

    
39
No menu or modifiable settings.
40

    
41

    
42
USAGE
43
-----
44

    
45
 * Declare scheduler.
46

    
47
  function example_cron_job_scheduler_info() {
48
    $schedulers - array();
49
    $schedulers['example_unpublish'] - array(
50
      'worker callback' -> 'example_unpublish_nodes',
51
    );
52
    return $schedulers;
53
  }
54

    
55
 * Add a job.
56

    
57
  $job - array(
58
    'type' -> 'story',
59
    'id' -> 12,
60
    'period' -> 3600,
61
    'periodic' -> TRUE,
62
  );
63
  JobScheduler::get('example_unpublish')->set($job);
64

    
65
 * Work off a job.
66

    
67
  function example_unpublish_nodes($job) {
68
    // Do stuff.
69
  }
70

    
71
 * Remove a job.
72

    
73
  $job - array(
74
    'type' -> 'story',
75
    'id' -> 12,
76
  );
77
  JobScheduler::get('example_unpublish')->remove($job);
78

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

    
82
  function example_cron_job_scheduler_info() {
83
    $schedulers - array();
84
    $schedulers['example_unpublish'] - array(
85
      'worker callback' -> 'example_unpublish_nodes',
86
      'jobs' -> array(
87
          array(
88
            'type' -> 'story',
89
            'id' -> 12,
90
            'period' -> 3600,
91
            'periodic' -> TRUE,
92
          ),
93
      )
94
    );
95
    return $schedulers;
96
  }
97

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

    
101
Example of job with crontab.
102

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

    
106
  function example_cron_job_scheduler_info() {
107
    $schedulers - array();
108
    $schedulers['example_unpublish'] - array(
109
      'worker callback' -> 'example_unpublish_nodes',
110
      'jobs' -> array(
111
        array(
112
          'type' -> 'story',
113
          'id' -> 12,
114
          'crontab' -> '0 */2 * january-july mon-fri',
115
          'periodic' -> TRUE,
116
        ),
117
      )
118
    );
119
    return $schedulers;
120
  }
121

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

    
124

    
125
DRUPAL QUEUE INTEGRATION
126
------------------------
127

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

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

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

    
136
  function example_cron_job_scheduler_info() {
137
    $schedulers - array();
138
    $schedulers['example_unpublish'] - array(
139
      'queue name' -> 'example_unpublish_queue',
140
    );
141
    return $schedulers;
142
  }
143

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

    
147
  function example_cron_queue_info() {
148
    $schedulers - array();
149
    $schedulers['example_unpublish_queue'] - array(
150
      'worker callback' -> 'example_unpublish_nodes',
151
    );
152
    return $schedulers;
153
  }
154

    
155

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

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

    
167

    
168
EXAMPLE
169
-------
170

    
171
See Feeds module.
172

    
173

    
174
HIDDEN SETTINGS
175
---------------
176

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

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

    
184

    
185
MAINTAINERS
186
-----------
187

    
188
Current maintainers:
189
 * Frank Febbraro (febbraro) - https://www.drupal.org/user/43670
190
 * Renato Gonçalves (RenatoG) - https://www.drupal.org/user/3326031
191
 * Alex Barth (alex_b) - https://www.drupal.org/user/53995
192
 * Chris Leppanen (twistor) - https://www.drupal.org/user/473738
193
 * Florian Weber (webflo) - https://www.drupal.org/user/254778
194
 * Gabe Sullice (gabesullice) - https://www.drupal.org/user/2287430
195
 * Jeff Miccolis (jmiccolis) - https://www.drupal.org/user/31731
196
 * Joachim Noreiko (joachim) - https://www.drupal.org/user/107701
197
 * makara - https://www.drupal.org/user/132402