|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bavix\Gearman; |
|
4
|
|
|
|
|
5
|
|
|
class Client extends \GearmanClient |
|
6
|
|
|
{ |
|
7
|
|
|
|
|
8
|
|
|
/** |
|
9
|
|
|
* Runs a single high priority task and returns a string representation of the |
|
10
|
|
|
* result. It is up to the GearmanClient and GearmanWorker to agree on the format |
|
11
|
|
|
* of the result. High priority tasks will get precedence over normal and low |
|
12
|
|
|
* priority tasks in the job queue. |
|
13
|
|
|
* |
|
14
|
|
|
* @link http://php.net/manual/en/gearmanclient.dohigh.php |
|
15
|
|
|
* @param string $function_name |
|
16
|
|
|
* @param string $workload |
|
17
|
|
|
* @param string $unique |
|
18
|
|
|
* @return string A string representing the results of running a task |
|
19
|
|
|
* |
|
20
|
|
|
* @codeCoverageIgnore |
|
21
|
|
|
*/ |
|
22
|
|
|
public function doHigh($function_name, $workload, $unique = null) |
|
23
|
|
|
{ |
|
24
|
|
|
return parent::doHigh( |
|
25
|
|
|
Task::getName($function_name), |
|
26
|
|
|
$workload, |
|
27
|
|
|
$unique |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Runs a single task and returns a string representation of the |
|
33
|
|
|
* result. It is up to the GearmanClient and GearmanWorker to agree on the format |
|
34
|
|
|
* of the result. Normal and high priority tasks will get precedence over low |
|
35
|
|
|
* priority tasks in the job queue. |
|
36
|
|
|
* |
|
37
|
|
|
* @link http://php.net/manual/en/gearmanclient.dolow.php |
|
38
|
|
|
* @param string $function_name |
|
39
|
|
|
* @param string $workload |
|
40
|
|
|
* @param string $unique |
|
41
|
|
|
* @return string A string representing the results of running a task |
|
42
|
|
|
* |
|
43
|
|
|
* @codeCoverageIgnore |
|
44
|
|
|
*/ |
|
45
|
|
|
public function doNormal($function_name, $workload, $unique = null) |
|
46
|
|
|
{ |
|
47
|
|
|
return parent::doNormal( |
|
48
|
|
|
Task::getName($function_name), |
|
49
|
|
|
$workload, |
|
50
|
|
|
$unique |
|
51
|
|
|
); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Runs a single low priority task and returns a string representation of the |
|
56
|
|
|
* result. It is up to the GearmanClient and GearmanWorker to agree on the format |
|
57
|
|
|
* of the result. Normal and high priority tasks will get precedence over low |
|
58
|
|
|
* priority tasks in the job queue. |
|
59
|
|
|
* |
|
60
|
|
|
* @link http://php.net/manual/en/gearmanclient.dolow.php |
|
61
|
|
|
* @param string $function_name |
|
62
|
|
|
* @param string $workload |
|
63
|
|
|
* @param string $unique |
|
64
|
|
|
* @return string A string representing the results of running a task |
|
65
|
|
|
* |
|
66
|
|
|
* @codeCoverageIgnore |
|
67
|
|
|
*/ |
|
68
|
|
|
public function doLow($function_name, $workload, $unique = null) |
|
69
|
|
|
{ |
|
70
|
|
|
return parent::doLow( |
|
71
|
|
|
Task::getName($function_name), |
|
72
|
|
|
$workload, |
|
73
|
|
|
$unique |
|
74
|
|
|
); |
|
75
|
|
|
} |
|
76
|
|
|
|
|
77
|
|
|
/** |
|
78
|
|
|
* Runs a task in the background, returning a job handle which can be used to get |
|
79
|
|
|
* the status of the running task. |
|
80
|
|
|
* |
|
81
|
|
|
* @link http://php.net/manual/en/gearmanclient.dobackground.php |
|
82
|
|
|
* @param string $function_name |
|
83
|
|
|
* @param string $workload |
|
84
|
|
|
* @param string $unique |
|
85
|
|
|
* @return string The job handle for the submitted task |
|
86
|
|
|
* |
|
87
|
|
|
* @codeCoverageIgnore |
|
88
|
|
|
*/ |
|
89
|
|
|
public function doBackground($function_name, $workload, $unique = null) |
|
90
|
|
|
{ |
|
91
|
|
|
return parent::doBackground( |
|
92
|
|
|
Task::getName($function_name), |
|
93
|
|
|
$workload, |
|
94
|
|
|
$unique |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Runs a high priority task in the background, returning a job handle which can be |
|
100
|
|
|
* used to get the status of the running task. High priority tasks take precedence |
|
101
|
|
|
* over normal and low priority tasks in the job queue. |
|
102
|
|
|
* |
|
103
|
|
|
* @link http://php.net/manual/en/gearmanclient.dohighbackground.php |
|
104
|
|
|
* @param string $function_name |
|
105
|
|
|
* @param string $workload |
|
106
|
|
|
* @param string $unique |
|
107
|
|
|
* @return string The job handle for the submitted task |
|
108
|
|
|
* |
|
109
|
|
|
* @codeCoverageIgnore |
|
110
|
|
|
*/ |
|
111
|
|
|
public function doHighBackground($function_name, $workload, $unique = null) |
|
112
|
|
|
{ |
|
113
|
|
|
return parent::doHighBackground( |
|
114
|
|
|
Task::getName($function_name), |
|
115
|
|
|
$workload, |
|
116
|
|
|
$unique |
|
117
|
|
|
); |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* Runs a low priority task in the background, returning a job handle which can be |
|
122
|
|
|
* used to get the status of the running task. Normal and high priority tasks take |
|
123
|
|
|
* precedence over low priority tasks in the job queue. |
|
124
|
|
|
* |
|
125
|
|
|
* @link http://php.net/manual/en/gearmanclient.dolowbackground.php |
|
126
|
|
|
* @param string $function_name |
|
127
|
|
|
* @param string $workload |
|
128
|
|
|
* @param string $unique |
|
129
|
|
|
* @return string The job handle for the submitted task |
|
130
|
|
|
* |
|
131
|
|
|
* @codeCoverageIgnore |
|
132
|
|
|
*/ |
|
133
|
|
|
public function doLowBackground($function_name, $workload, $unique = null) |
|
134
|
|
|
{ |
|
135
|
|
|
return parent::doLowBackground( |
|
136
|
|
|
Task::getName($function_name), |
|
137
|
|
|
$workload, |
|
138
|
|
|
$unique |
|
139
|
|
|
); |
|
140
|
|
|
} |
|
141
|
|
|
|
|
142
|
|
|
/** |
|
143
|
|
|
* Adds a task to be run in parallel with other tasks. Call this method for all the |
|
144
|
|
|
* tasks to be run in parallel, then call GearmanClient::runTasks to perform the |
|
145
|
|
|
* work. Note that enough workers need to be available for the tasks to all run in |
|
146
|
|
|
* parallel. |
|
147
|
|
|
* |
|
148
|
|
|
* @link http://php.net/manual/en/gearmanclient.addtask.php |
|
149
|
|
|
* @param string $function_name |
|
150
|
|
|
* @param string $workload |
|
151
|
|
|
* @param mixed $context |
|
152
|
|
|
* @param string $unique |
|
153
|
|
|
* @return \GearmanTask A GearmanTask object or false if the task could not be added |
|
154
|
|
|
* |
|
155
|
|
|
* @codeCoverageIgnore |
|
156
|
|
|
*/ |
|
157
|
|
|
public function addTask($function_name, $workload, $context = null, $unique = null) |
|
158
|
|
|
{ |
|
159
|
|
|
return parent::addTask( |
|
160
|
|
|
Task::getName($function_name), |
|
161
|
|
|
$workload, |
|
162
|
|
|
$context, |
|
163
|
|
|
$unique |
|
164
|
|
|
); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* Adds a high priority task to be run in parallel with other tasks. Call this |
|
169
|
|
|
* method for all the high priority tasks to be run in parallel, then call |
|
170
|
|
|
* GearmanClient::runTasks to perform the work. Tasks with a high priority will be |
|
171
|
|
|
* selected from the queue before those of normal or low priority. |
|
172
|
|
|
* |
|
173
|
|
|
* @link http://php.net/manual/en/gearmanclient.addtaskhigh.php |
|
174
|
|
|
* @param string $function_name |
|
175
|
|
|
* @param string $workload |
|
176
|
|
|
* @param mixed $context |
|
177
|
|
|
* @param string $unique |
|
178
|
|
|
* @return \GearmanTask A GearmanTask object or false if the task could not be added |
|
179
|
|
|
* |
|
180
|
|
|
* @codeCoverageIgnore |
|
181
|
|
|
*/ |
|
182
|
|
|
public function addTaskHigh($function_name, $workload, $context = null, $unique = null) |
|
183
|
|
|
{ |
|
184
|
|
|
return parent::addTaskHigh( |
|
185
|
|
|
Task::getName($function_name), |
|
186
|
|
|
$workload, |
|
187
|
|
|
$context, |
|
188
|
|
|
$unique |
|
189
|
|
|
); |
|
190
|
|
|
} |
|
191
|
|
|
|
|
192
|
|
|
/** |
|
193
|
|
|
* Adds a low priority background task to be run in parallel with other tasks. Call |
|
194
|
|
|
* this method for all the tasks to be run in parallel, then call |
|
195
|
|
|
* GearmanClient::runTasks to perform the work. Tasks with a low priority will be |
|
196
|
|
|
* selected from the queue after those of normal or low priority. |
|
197
|
|
|
* |
|
198
|
|
|
* @link http://php.net/manual/en/gearmanclient.addtasklow.php |
|
199
|
|
|
* @param string $function_name |
|
200
|
|
|
* @param string $workload |
|
201
|
|
|
* @param mixed $context |
|
202
|
|
|
* @param string $unique |
|
203
|
|
|
* @return \GearmanTask A GearmanTask object or false if the task could not be added |
|
204
|
|
|
* |
|
205
|
|
|
* @codeCoverageIgnore |
|
206
|
|
|
*/ |
|
207
|
|
|
public function addTaskLow($function_name, $workload, $context = null, $unique = null) |
|
208
|
|
|
{ |
|
209
|
|
|
return parent::addTaskLow( |
|
210
|
|
|
Task::getName($function_name), |
|
211
|
|
|
$workload, |
|
212
|
|
|
$context, |
|
213
|
|
|
$unique |
|
214
|
|
|
); |
|
215
|
|
|
} |
|
216
|
|
|
|
|
217
|
|
|
/** |
|
218
|
|
|
* Adds a background task to be run in parallel with other tasks. Call this method |
|
219
|
|
|
* for all the tasks to be run in parallel, then call GearmanClient::runTasks to |
|
220
|
|
|
* perform the work. |
|
221
|
|
|
* |
|
222
|
|
|
* @link http://php.net/manual/en/gearmanclient.addtaskbackground.php |
|
223
|
|
|
* @param string $function_name |
|
224
|
|
|
* @param string $workload |
|
225
|
|
|
* @param mixed $context |
|
226
|
|
|
* @param string $unique |
|
227
|
|
|
* @return \GearmanTask A GearmanTask object or false if the task could not be added |
|
228
|
|
|
* |
|
229
|
|
|
* @codeCoverageIgnore |
|
230
|
|
|
*/ |
|
231
|
|
|
public function addTaskBackground($function_name, $workload, $context = null, $unique = null) |
|
232
|
|
|
{ |
|
233
|
|
|
return parent::addTaskBackground( |
|
234
|
|
|
Task::getName($function_name), |
|
235
|
|
|
$workload, |
|
236
|
|
|
$context, |
|
237
|
|
|
$unique |
|
238
|
|
|
); |
|
239
|
|
|
} |
|
240
|
|
|
|
|
241
|
|
|
/** |
|
242
|
|
|
* Adds a high priority background task to be run in parallel with other tasks. |
|
243
|
|
|
* Call this method for all the tasks to be run in parallel, then call |
|
244
|
|
|
* GearmanClient::runTasks to perform the work. Tasks with a high priority will be |
|
245
|
|
|
* selected from the queue before those of normal or low priority. |
|
246
|
|
|
* |
|
247
|
|
|
* @link http://php.net/manual/en/gearmanclient.addtaskhighbackground.php |
|
248
|
|
|
* @param string $function_name |
|
249
|
|
|
* @param string $workload |
|
250
|
|
|
* @param mixed $context |
|
251
|
|
|
* @param string $unique |
|
252
|
|
|
* @return \GearmanTask A GearmanTask object or false if the task could not be added |
|
253
|
|
|
* |
|
254
|
|
|
* @codeCoverageIgnore |
|
255
|
|
|
*/ |
|
256
|
|
|
public function addTaskHighBackground($function_name, $workload, $context = null, $unique = null) |
|
257
|
|
|
{ |
|
258
|
|
|
return parent::addTaskHighBackground( |
|
259
|
|
|
Task::getName($function_name), |
|
260
|
|
|
$workload, |
|
261
|
|
|
$context, |
|
262
|
|
|
$unique |
|
263
|
|
|
); |
|
264
|
|
|
} |
|
265
|
|
|
|
|
266
|
|
|
/** |
|
267
|
|
|
* Adds a low priority background task to be run in parallel with other tasks. Call |
|
268
|
|
|
* this method for all the tasks to be run in parallel, then call |
|
269
|
|
|
* GearmanClient::runTasks to perform the work. Tasks with a low priority will be |
|
270
|
|
|
* selected from the queue after those of normal or high priority. |
|
271
|
|
|
* |
|
272
|
|
|
* @link http://php.net/manual/en/gearmanclient.addtasklowbackground.php |
|
273
|
|
|
* @param string $function_name |
|
274
|
|
|
* @param string $workload |
|
275
|
|
|
* @param mixed $context |
|
276
|
|
|
* @param string $unique |
|
277
|
|
|
* @return \GearmanTask A GearmanTask object or false if the task could not be added |
|
278
|
|
|
* |
|
279
|
|
|
* @codeCoverageIgnore |
|
280
|
|
|
*/ |
|
281
|
|
|
public function addTaskLowBackground($function_name, $workload, $context = null, $unique = null) |
|
282
|
|
|
{ |
|
283
|
|
|
return parent::addTaskLowBackground( |
|
284
|
|
|
Task::getName($function_name), |
|
285
|
|
|
$workload, |
|
286
|
|
|
$context, |
|
287
|
|
|
$unique |
|
288
|
|
|
); |
|
289
|
|
|
} |
|
290
|
|
|
|
|
291
|
|
|
} |
|
292
|
|
|
|