1 | <?php |
||
26 | class WorkerClass |
||
27 | { |
||
28 | /** |
||
29 | * @var string |
||
30 | * |
||
31 | * Default description when is not defined |
||
32 | */ |
||
33 | const DEFAULT_DESCRIPTION = 'No description is defined'; |
||
34 | |||
35 | /** |
||
36 | * @var string |
||
37 | * |
||
38 | * Namespace of worker class |
||
39 | */ |
||
40 | private $namespace; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | * |
||
45 | * Class name of worker |
||
46 | */ |
||
47 | private $className; |
||
48 | |||
49 | /** |
||
50 | * @var string |
||
51 | * |
||
52 | * Filename of worker |
||
53 | */ |
||
54 | private $fileName; |
||
55 | |||
56 | /** |
||
57 | * @var string |
||
58 | * |
||
59 | * Callable name for this job. |
||
60 | * If is setted on annotations, this value will be used. |
||
61 | * Otherwise, natural method name will be used. |
||
62 | */ |
||
63 | private $callableName; |
||
64 | |||
65 | /** |
||
66 | * @var string |
||
67 | * |
||
68 | * Service alias if this worker is wanted to be built by dependency injection |
||
69 | */ |
||
70 | private $service; |
||
71 | |||
72 | /** |
||
73 | * @var string |
||
74 | * |
||
75 | * Description of Job |
||
76 | */ |
||
77 | private $description; |
||
78 | |||
79 | /** |
||
80 | * @var integer |
||
81 | * |
||
82 | * Number of iterations this job will be alive before die |
||
83 | */ |
||
84 | private $iterations; |
||
85 | |||
86 | /** |
||
87 | * @var string |
||
88 | * |
||
89 | * Default method this job will be call into Gearman client |
||
90 | */ |
||
91 | private $defaultMethod; |
||
92 | |||
93 | /** |
||
94 | * @var int |
||
95 | * |
||
96 | * Job minimum execution time |
||
97 | */ |
||
98 | private $minimumExecutionTime; |
||
99 | |||
100 | /** |
||
101 | * @var int |
||
102 | * |
||
103 | * Timeout for idle job |
||
104 | */ |
||
105 | private $timeout; |
||
106 | |||
107 | /** |
||
108 | * @var array |
||
109 | * |
||
110 | * Collection of servers to connect |
||
111 | */ |
||
112 | private $servers; |
||
113 | |||
114 | /** |
||
115 | * @var JobCollection |
||
116 | * |
||
117 | * All jobs inside Worker |
||
118 | */ |
||
119 | private $jobCollection; |
||
120 | |||
121 | /** |
||
122 | * The prefix for all job names |
||
123 | * |
||
124 | * @var string $jobPrefix |
||
125 | */ |
||
126 | private $jobPrefix = null; |
||
127 | |||
128 | /** |
||
129 | * Retrieves all jobs available from worker |
||
130 | * |
||
131 | * @param WorkAnnotation $workAnnotation workAnnotation class |
||
132 | * @param \ReflectionClass $reflectionClass Reflexion class |
||
133 | * @param Reader $reader Reader class |
||
134 | * @param array $servers Array of servers defined for Worker |
||
135 | * @param array $defaultSettings Default settings for Worker |
||
136 | */ |
||
137 | 3 | public function __construct(WorkAnnotation $workAnnotation, \ReflectionClass $reflectionClass, Reader $reader, array $servers, array $defaultSettings) |
|
185 | |||
186 | /** |
||
187 | * Load servers |
||
188 | * |
||
189 | * If any server is defined in JobAnnotation, this one is used. |
||
190 | * Otherwise is used servers set in Class |
||
191 | * |
||
192 | * @param WorkAnnotation $workAnnotation WorkAnnotation class |
||
193 | * @param array $servers Array of servers defined for Worker |
||
194 | * |
||
195 | * @return array Servers |
||
196 | */ |
||
197 | 3 | private function loadServers(WorkAnnotation $workAnnotation, array $servers) |
|
211 | |||
212 | /** |
||
213 | * Load iterations |
||
214 | * |
||
215 | * If iterations is defined in WorkAnnotation, this one is used. |
||
216 | * Otherwise is used set in Class |
||
217 | * |
||
218 | * @param WorkAnnotation $workAnnotation WorkAnnotation class |
||
219 | * @param array $defaultSettings Default settings for Worker |
||
220 | * |
||
221 | * @return integer Iteration |
||
222 | */ |
||
223 | 3 | private function loadIterations(WorkAnnotation $workAnnotation, array $defaultSettings) |
|
229 | |||
230 | /** |
||
231 | * Load defaultMethod |
||
232 | * |
||
233 | * If defaultMethod is defined in WorkAnnotation, this one is used. |
||
234 | * Otherwise is used set in Class |
||
235 | * |
||
236 | * @param WorkAnnotation $workAnnotation WorkAnnotation class |
||
237 | * @param array $defaultSettings Default settings for Worker |
||
238 | * |
||
239 | * @return string Default method |
||
240 | */ |
||
241 | 3 | private function loadDefaultMethod(WorkAnnotation $workAnnotation, array $defaultSettings) |
|
247 | |||
248 | /** |
||
249 | * Load minimumExecutionTime |
||
250 | * |
||
251 | * If minimumExecutionTime is defined in JobAnnotation, this one is used. |
||
252 | * Otherwise is used set in Class |
||
253 | * |
||
254 | * @param WorkAnnotation $workAnnotation |
||
255 | * @param array $defaultSettings |
||
256 | * |
||
257 | * @return int |
||
258 | */ |
||
259 | 3 | private function loadMinimumExecutionTime(WorkAnnotation $workAnnotation, array $defaultSettings) |
|
265 | |||
266 | /** |
||
267 | * Load timeout |
||
268 | * |
||
269 | * If timeout is defined in JobAnnotation, this one is used. |
||
270 | * Otherwise is used set in Class |
||
271 | * |
||
272 | * @param WorkAnnotation $workAnnotation |
||
273 | * @param array $defaultSettings |
||
274 | * |
||
275 | * @return int |
||
276 | */ |
||
277 | 3 | private function loadTimeout(WorkAnnotation $workAnnotation, array $defaultSettings) |
|
283 | |||
284 | /** |
||
285 | * Creates job collection of worker |
||
286 | * |
||
287 | * @param \ReflectionClass $reflectionClass Reflexion class |
||
288 | * @param Reader $reader ReaderAnnotation class |
||
289 | * |
||
290 | * @return JobCollection self Object |
||
291 | */ |
||
292 | 3 | private function createJobCollection(\ReflectionClass $reflectionClass, Reader $reader) |
|
330 | |||
331 | /** |
||
332 | * Retrieve all Worker data in cache format |
||
333 | * |
||
334 | * @return array |
||
335 | */ |
||
336 | 3 | public function toArray() |
|
353 | |||
354 | } |
||
355 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.