Révision 082b75eb
Ajouté par Assos Assos il y a environ 6 ans
drupal7/sites/all/modules/job_scheduler/README.txt | ||
---|---|---|
1 |
|
|
2 |
Job Scheduler |
|
3 |
============= |
|
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 |
------------ |
|
4 | 17 |
|
5 | 18 |
Simple API for scheduling tasks once at a predetermined time or periodically at |
6 | 19 |
a fixed interval. |
7 | 20 |
|
8 | 21 |
|
9 |
Usage |
|
10 |
===== |
|
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 |
|
|
11 | 41 |
|
12 |
Declare scheduler. |
|
42 |
USAGE |
|
43 |
----- |
|
44 |
|
|
45 |
* Declare scheduler. |
|
13 | 46 |
|
14 | 47 |
function example_cron_job_scheduler_info() { |
15 |
$schedulers = array();
|
|
16 |
$schedulers['example_unpublish'] = array(
|
|
17 |
'worker callback' => 'example_unpublish_nodes',
|
|
48 |
$schedulers - array();
|
|
49 |
$schedulers['example_unpublish'] - array(
|
|
50 |
'worker callback' -> 'example_unpublish_nodes',
|
|
18 | 51 |
); |
19 | 52 |
return $schedulers; |
20 | 53 |
} |
21 | 54 |
|
22 |
Add a job. |
|
55 |
* Add a job.
|
|
23 | 56 |
|
24 |
$job = array(
|
|
25 |
'type' => 'story',
|
|
26 |
'id' => 12,
|
|
27 |
'period' => 3600,
|
|
28 |
'periodic' => TRUE,
|
|
57 |
$job - array(
|
|
58 |
'type' -> 'story',
|
|
59 |
'id' -> 12,
|
|
60 |
'period' -> 3600,
|
|
61 |
'periodic' -> TRUE,
|
|
29 | 62 |
); |
30 | 63 |
JobScheduler::get('example_unpublish')->set($job); |
31 | 64 |
|
32 |
Work off a job. |
|
65 |
* Work off a job.
|
|
33 | 66 |
|
34 | 67 |
function example_unpublish_nodes($job) { |
35 | 68 |
// Do stuff. |
36 | 69 |
} |
37 | 70 |
|
38 |
Remove a job. |
|
71 |
* Remove a job.
|
|
39 | 72 |
|
40 |
$job = array(
|
|
41 |
'type' => 'story',
|
|
42 |
'id' => 12,
|
|
73 |
$job - array(
|
|
74 |
'type' -> 'story',
|
|
75 |
'id' -> 12,
|
|
43 | 76 |
); |
44 | 77 |
JobScheduler::get('example_unpublish')->remove($job); |
45 | 78 |
|
46 |
Optionally jobs can declared together with a schedule in a hook_cron_job_scheduler_info(). |
|
79 |
Optionally jobs can declared together with a schedule in a: |
|
80 |
hook_cron_job_scheduler_info(). |
|
47 | 81 |
|
48 | 82 |
function example_cron_job_scheduler_info() { |
49 |
$schedulers = array(); |
|
50 |
$schedulers['example_unpublish'] = array( |
|
51 |
'worker callback' => 'example_unpublish_nodes', |
|
52 |
'jobs' => array( |
|
53 |
array('type' => 'story', 'id' => 12, 'period' => 3600, 'periodic' => TRUE), |
|
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 |
), |
|
54 | 93 |
) |
55 | 94 |
); |
56 | 95 |
return $schedulers; |
57 | 96 |
} |
58 | 97 |
|
59 |
Jobs can have a 'crontab' instead of a period. Crontab syntax are Unix-like formatted crontab lines. |
|
98 |
Jobs can have a 'crontab' instead of a period. Crontab syntax are Unix-like |
|
99 |
formatted crontab lines. |
|
100 |
|
|
60 | 101 |
Example of job with crontab. |
61 | 102 |
|
62 |
// This will create a job that will be triggered from monday to friday, from january to july, every two hours |
|
103 |
This will create a job that will be triggered from monday to friday, from |
|
104 |
january to july, every two hours: |
|
105 |
|
|
63 | 106 |
function example_cron_job_scheduler_info() { |
64 |
$schedulers = array(); |
|
65 |
$schedulers['example_unpublish'] = array( |
|
66 |
'worker callback' => 'example_unpublish_nodes', |
|
67 |
'jobs' => array( |
|
68 |
array('type' => 'story', 'id' => 12, 'crontab' => '0 */2 * january-july mon-fri', 'periodic' => TRUE), |
|
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 |
), |
|
69 | 117 |
) |
70 | 118 |
); |
71 | 119 |
return $schedulers; |
72 | 120 |
} |
73 | 121 |
|
74 |
Read more about crontab syntax, http://linux.die.net/man/5/crontab |
|
122 |
Read more about crontab syntax: http://linux.die.net/man/5/crontab |
|
123 |
|
|
75 | 124 |
|
76 |
Drupal Queue integration
|
|
77 |
========================
|
|
125 |
DRUPAL QUEUE INTEGRATION
|
|
126 |
------------------------
|
|
78 | 127 |
|
79 | 128 |
Optionally, at the scheduled time Job Scheduler can queue a job for execution, |
80 | 129 |
rather than executing the job directly. This is useful when many jobs need to |
... | ... | |
85 | 134 |
Instead of declaring a worker callback, declare a queue name. |
86 | 135 |
|
87 | 136 |
function example_cron_job_scheduler_info() { |
88 |
$schedulers = array();
|
|
89 |
$schedulers['example_unpublish'] = array(
|
|
90 |
'queue name' => 'example_unpublish_queue',
|
|
137 |
$schedulers - array();
|
|
138 |
$schedulers['example_unpublish'] - array(
|
|
139 |
'queue name' -> 'example_unpublish_queue',
|
|
91 | 140 |
); |
92 | 141 |
return $schedulers; |
93 | 142 |
} |
... | ... | |
96 | 145 |
pattern the queue callback contains the actual worker callback. |
97 | 146 |
|
98 | 147 |
function example_cron_queue_info() { |
99 |
$schedulers = array();
|
|
100 |
$schedulers['example_unpublish_queue'] = array(
|
|
101 |
'worker callback' => 'example_unpublish_nodes',
|
|
148 |
$schedulers - array();
|
|
149 |
$schedulers['example_unpublish_queue'] - array(
|
|
150 |
'worker callback' -> 'example_unpublish_nodes',
|
|
102 | 151 |
); |
103 | 152 |
return $schedulers; |
104 | 153 |
} |
... | ... | |
115 | 164 |
JobScheduler::get('example_unpublish')->set($job); |
116 | 165 |
} |
117 | 166 |
|
118 |
Example |
|
119 |
======= |
|
167 |
|
|
168 |
EXAMPLE |
|
169 |
------- |
|
120 | 170 |
|
121 | 171 |
See Feeds module. |
122 | 172 |
|
123 | 173 |
|
124 |
Hidden settings
|
|
125 |
===============
|
|
174 |
HIDDEN SETTINGS
|
|
175 |
---------------
|
|
126 | 176 |
|
127 | 177 |
Hidden settings are variables that you can define by adding them to the $conf |
128 | 178 |
array in your settings.php file. |
... | ... | |
130 | 180 |
Name: 'job_scheduler_class_' . $name |
131 | 181 |
Default: 'JobScheduler' |
132 | 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 |
Formats disponibles : Unified diff
Weekly update of contrib modules