|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Bavix\Gearman; |
|
4
|
|
|
|
|
5
|
|
|
use Bavix\Helpers\Closure; |
|
6
|
|
|
|
|
7
|
|
|
class Worker extends \GearmanWorker |
|
8
|
|
|
{ |
|
9
|
|
|
|
|
10
|
|
|
/** |
|
11
|
|
|
* Registers a function name with the job server with an optional timeout. The |
|
12
|
|
|
* timeout specifies how many seconds the server will wait before marking a job as |
|
13
|
|
|
* failed. If the timeout is set to zero, there is no timeout. |
|
14
|
|
|
* |
|
15
|
|
|
* @link http://php.net/manual/en/gearmanworker.register.php |
|
16
|
|
|
* @param string $function_name The name of a function to register with the job |
|
17
|
|
|
* server |
|
18
|
|
|
* @param int $timeout An interval of time in seconds |
|
19
|
|
|
* @return bool A standard Gearman return value |
|
20
|
|
|
* |
|
21
|
|
|
* @codeCoverageIgnore |
|
22
|
|
|
*/ |
|
23
|
|
|
public function register($function_name, $timeout = null) |
|
24
|
|
|
{ |
|
25
|
|
|
return parent::register( |
|
26
|
|
|
Task::getName($function_name), |
|
27
|
|
|
$timeout |
|
28
|
|
|
); |
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Unregisters a function name with the job servers ensuring that no more jobs (for |
|
33
|
|
|
* that function) are sent to this worker. |
|
34
|
|
|
* |
|
35
|
|
|
* @link http://php.net/manual/en/gearmanworker.unregister.php |
|
36
|
|
|
* @param string $function_name The name of a function to register with the job |
|
37
|
|
|
* server |
|
38
|
|
|
* @return bool A standard Gearman return value |
|
39
|
|
|
* |
|
40
|
|
|
* @codeCoverageIgnore |
|
41
|
|
|
*/ |
|
42
|
|
|
public function unregister($function_name) |
|
43
|
|
|
{ |
|
44
|
|
|
return parent::unregister( |
|
45
|
|
|
Task::getName($function_name) |
|
46
|
|
|
); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Registers a function name with the job server and specifies a callback |
|
51
|
|
|
* corresponding to that function. Optionally specify extra application context |
|
52
|
|
|
* data to be used when the callback is called and a timeout. |
|
53
|
|
|
* |
|
54
|
|
|
* @link http://php.net/manual/en/gearmanworker.addfunction.php |
|
55
|
|
|
* @param string $function_name The name of a function to register with the job |
|
56
|
|
|
* server |
|
57
|
|
|
* @param callback $function A callback that gets called when a job for the |
|
58
|
|
|
* registered function name is submitted |
|
59
|
|
|
* @param mixed $context A reference to arbitrary application context data that can |
|
60
|
|
|
* be modified by the worker function |
|
61
|
|
|
* @param int $timeout An interval of time in seconds |
|
62
|
|
|
* @return bool |
|
63
|
|
|
* |
|
64
|
|
|
* @codeCoverageIgnore |
|
65
|
|
|
*/ |
|
66
|
|
|
public function addFunction($function_name, $function, $context = null, $timeout = 0) |
|
67
|
|
|
{ |
|
68
|
|
|
return parent::addFunction( |
|
69
|
|
|
Task::getName($function_name), |
|
70
|
|
|
Closure::fromCallable($function), |
|
71
|
|
|
$context, |
|
72
|
|
|
$timeout |
|
73
|
|
|
); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
} |
|
77
|
|
|
|