-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathultimate_cron.api.php
270 lines (253 loc) · 6.8 KB
/
ultimate_cron.api.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
<?php
/**
* @file
* Hooks provided by Ultimate Cron.
*/
use Drupal\ultimate_cron\Entity\CronJob;
/**
* @addtogroup hooks
* @{
*/
/**
* Inform Ultimate Cron about cron jobs.
*
* Note that the result of this hook is cached.
*
* @return array
* Array of cron jobs, keyed by name.
* - "title": (optional) The title of the cron job. If not provided, the
* name of the cron job will be used.
* - "file": (optional) The file where the callback lives.
* - "module": The module where this job lives.
* - "file path": (optional) The path to the directory containing the file
* specified in "file". This defaults to the path to the module
* implementing the hook.
* - "callback": (optional) The callback to call when running the job.
* Defaults to the job name.
* - "callback arguments": (optional) Arguments for the callback. Defaults
* to array().
* - "enabled": (optional) Initial state of the job. Defaults to TRUE.
* - "tags": (optional) Tags for the job. Defaults to array().
* - "settings": (optional) Default settings (plugin type) for this job.
* Example of a job declaring some default settings for a plugin called
* "some_plugin":
* 'settings' => array(
* 'some_plugin' => array(
* 'some_value' => 60,
* ),
* ),
* - "scheduler": (optional) Default scheduler (plugin type) for this job.
* Example of a job using the crontab scheduler as default:
* 'scheduler' => array(
* 'name' => 'crontab',
* 'crontab' => array(
* 'rules' => array('* * * * *'),
* ),
* ),
* - "launcher": (optional) Default launcher (plugin type) for this job.
* Example of a job using the serial launcher as default:
* 'launcher' => array(
* 'name' => 'serial',
* 'serial' => array(
* 'thread' => 'any',
* ),
* ),
* - "logger": (optional) Default logger (plugin type) for this job.
* Example of a job using the cache logger as default:
* 'logger' => array(
* 'name' => 'cache',
* 'cache' => array(
* 'bin' => 'mycachebin',
* ),
* ),
*/
function hook_cronapi() {
$items = array();
$items['example_my_cron_job_1'] = array(
'title' => t('This is my cron job #1'),
'file' => 'example.jobs.inc',
'file path' => drupal_get_path('module', 'example') . '/cron',
'callback' => 'example_my_cron_job_callback',
'callback arguments' => array('cronjob1'),
'enabled' => FALSE,
'tags' => array('example'),
'settings' => array(
'example_plugin' => array(
'example_setting' => 'example_value',
),
),
'scheduler' => array(
'name' => 'crontab',
'crontab' => array(
'rules' => array('* * * * *'),
),
),
'launcher' => array(
'name' => 'serial',
'serial' => array(
'thread' => 'any',
),
),
'logger' => array(
'name' => 'cache',
'cache' => array(
'bin' => 'my_cache_bin',
),
),
);
return $items;
}
/**
* Alter the output of hook_cronapi() and hook_cron().
*
* Note that the result of this hook is cached just like hook_cronapi().
*
* This can hook can also be implemented inside a plugin, but with a
* slight difference. Inside the plugin, the hook is not cached and it operates
* on an array of UltimateCronJob objects instead of hook definitions.
*
* @param array &$items
* Hooks defined in the system.
*/
function hook_cron_alter(&$items) {
$items['example_my_cron_job_1']['title'] = 'NEW TITLE FOR EXAMPLE CRON JOB #1! HA!';
}
/**
* Provide easy hooks for Ultimate Cron.
*
* Ultimate Cron has a built-in set of easy hooks:
* - hook_cron_hourly().
* - hook_cron_daily().
* - hook_cron_nightly().
* - hook_cron_weekly().
* - hook_cron_monthly().
* - hook_cron_yearly().
*
* This hook makes it possible to provide custom easy hooks.
*
* @return array
* Array of easy hook definitions.
*/
function hook_cron_easy_hooks() {
return array(
'cron_fullmoonly' => array(
'title' => 'Run at full moon',
'scheduler' => array(
'name' => 'moonphase',
'moonphase' => array(
'phase' => 'full',
),
),
)
);
}
/**
* Alter easy hooks.
*
* @param array &$easy_hooks
* Easy hook definitions.
*/
function hook_cron_easy_hooks_alter(&$easy_hooks) {
$easy_hooks['cron_fullmoonly']['scheduler']['moonphase']['phase'] = 'new';
}
/**
* The following hooks are invoked during the jobs life cycle,
* from schedule to finish. The chronological order is:
*
* cron_pre_schedule
* cron_post_schedule
* cron_pre_launch
* cron_pre_launch(*)
* cron_pre_run
* cron_pre_invoke
* cron_post_invoke
* cron_post_run
* cron_post_launch(*)
*
* Depending on how the launcher works, the hook_cron_post_launch() may be
* invoked before or after hook_cron_post_run() or somewhere in between.
* An example of this is the Background Process launcher, which launches
* the job in a separate thread. After the launch, hook_cron_post_launch()
* is invoked, but the run/invoke hooks are invoked simultaneously in a
* separate thread.
*
* All of these hooks can also be implemented inside a plugin as a method.
*/
/**
* Invoked just before a job is asked for its schedule.
*
* @param CronJob $job
* The job being queried.
*/
function hook_pre_schedule($job) {
}
/**
* Invoked after a job has been asked for its schedule.
*
* @param CronJob $job
* The job being queried.
*/
function hook_post_schedule($job) {
}
/**
* Invoked just before a job is launched.
*
* @param CronJob $job
* The job being launched.
*/
function hook_pre_launch($job) {
}
/**
* Invoked after a job has been launched.
*
* @param CronJob $job
* The job that was launched.
*/
function hook_post_launch($job) {
}
/**
* Invoked just before a job is being run.
*
* @param CronJob $job
* The job being run.
*/
function hook_pre_run($job) {
}
/**
* Invoked after a job has been run.
*
* @param CronJob $job
* The job that was run.
*/
function hook_post_run($job) {
}
/**
* Invoked just before a job is asked for its schedule.
*
* @param CronJob $job
* The job being invoked.
*/
function hook_pre_invoke($job) {
}
/**
* Invoked after a job has been invoked.
*
* @param CronJob $job
* The job that was invoked.
*/
function hook_post_invoke($job) {
}
/**
* Alter the allowed operations for a given job on the export UI page.
*
* This hook can also be implemented inside a plugin as a method:
* build_operations_alter($job, &$allowed_operations). It will only be
* run for the currently active plugin for the job.
*
* @param CronJob $job
* The job in question.
* @param array &$allowed_operations
* Allowed operations for this job.
*/
function hook_ultimate_cron_plugin_build_operations($job, &$allowed_operations) {
}