|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\Model; |
|
4
|
|
|
|
|
5
|
|
|
abstract class Worker |
|
6
|
|
|
{ |
|
7
|
|
|
protected $jobManager; |
|
8
|
|
|
protected $jobClass; |
|
9
|
|
|
protected $job; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @return string |
|
13
|
|
|
*/ |
|
14
|
13 |
|
public function getJobClass() |
|
15
|
|
|
{ |
|
16
|
13 |
|
return $this->jobClass; |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* @param string $jobClass |
|
21
|
|
|
*/ |
|
22
|
12 |
|
public function setJobClass($jobClass) |
|
23
|
|
|
{ |
|
24
|
12 |
|
$this->jobClass = $jobClass; |
|
25
|
12 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* @param JobManagerInterface $jobManager |
|
29
|
|
|
*/ |
|
30
|
22 |
|
public function setJobManager(JobManagerInterface $jobManager) |
|
31
|
|
|
{ |
|
32
|
22 |
|
$this->jobManager = $jobManager; |
|
33
|
22 |
|
} |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* @return |
|
37
|
|
|
*/ |
|
38
|
61 |
|
public function getJobManager() |
|
39
|
|
|
{ |
|
40
|
61 |
|
return $this->jobManager; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* @param int|null $time |
|
45
|
|
|
* @param bool $batch |
|
46
|
|
|
* @param int|null $priority |
|
47
|
|
|
*/ |
|
48
|
18 |
|
public function at($time = null, $batch = false, $priority = null) |
|
49
|
|
|
{ |
|
50
|
18 |
|
if (null === $time) { |
|
51
|
|
|
$time = time(); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
18 |
|
if ($time) { |
|
55
|
18 |
|
$dateTime = new \DateTime(); |
|
56
|
18 |
|
$dateTime->setTimestamp($time); |
|
57
|
18 |
|
} else { |
|
58
|
|
|
$dateTime = null; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
18 |
|
return new $this->jobClass($this, $batch, $priority, $dateTime); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param int $delay Amount of time to delay |
|
66
|
|
|
* @param int|null $priority |
|
67
|
|
|
*/ |
|
68
|
15 |
|
public function later($delay = 0, $priority = null) |
|
69
|
|
|
{ |
|
70
|
15 |
|
return $this->batchOrLaterDelay($delay, false, $priority); |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
16 |
|
public function batchOrLaterDelay($delay = 0, $batch = false, $priority = null) |
|
74
|
|
|
{ |
|
75
|
16 |
|
$job = $this->at(time() + $delay, $batch, $priority); |
|
76
|
16 |
|
$job->setDelay($delay); |
|
77
|
|
|
|
|
78
|
16 |
|
return $job; |
|
79
|
|
|
} |
|
80
|
|
|
|
|
81
|
|
|
/** |
|
82
|
|
|
* @param int $delay Amount of time to delay |
|
83
|
|
|
* @param int|null $priority |
|
84
|
|
|
*/ |
|
85
|
3 |
|
public function batchLater($delay = 0, $priority = null) |
|
86
|
|
|
{ |
|
87
|
3 |
|
return $this->batchOrLaterDelay($delay, true, $priority); |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
/** |
|
91
|
|
|
* @param int|null $time |
|
92
|
|
|
* @param int|null $priority |
|
93
|
|
|
*/ |
|
94
|
1 |
|
public function batchAt($time = null, $priority = null) |
|
95
|
|
|
{ |
|
96
|
1 |
|
return $this->at($time, true, $priority); |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
abstract public function getName(); |
|
100
|
|
|
} |
|
101
|
|
|
|