|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Dtc\QueueBundle\Redis; |
|
4
|
|
|
|
|
5
|
|
|
use Dtc\QueueBundle\Manager\JobIdTrait; |
|
6
|
|
|
use Dtc\QueueBundle\Manager\JobTimingManager; |
|
7
|
|
|
use Dtc\QueueBundle\Manager\PriorityJobManager; |
|
8
|
|
|
use Dtc\QueueBundle\Manager\RunManager; |
|
9
|
|
|
use Dtc\QueueBundle\Manager\VerifyTrait; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* For future implementation. |
|
13
|
|
|
*/ |
|
14
|
|
|
abstract class BaseJobManager extends PriorityJobManager |
|
15
|
|
|
{ |
|
16
|
|
|
use JobIdTrait; |
|
17
|
|
|
use VerifyTrait; |
|
18
|
|
|
|
|
19
|
|
|
/** @var RedisInterface */ |
|
20
|
|
|
protected $redis; |
|
21
|
|
|
|
|
22
|
|
|
/** @var string */ |
|
23
|
|
|
protected $cacheKeyPrefix; |
|
24
|
|
|
|
|
25
|
|
|
protected $hostname; |
|
26
|
|
|
protected $pid; |
|
27
|
|
|
|
|
28
|
|
|
/** |
|
29
|
|
|
* @param string $cacheKeyPrefix |
|
30
|
|
|
*/ |
|
31
|
2 |
|
public function __construct(RunManager $runManager, JobTimingManager $jobTimingManager, $jobClass, $cacheKeyPrefix) |
|
32
|
|
|
{ |
|
33
|
2 |
|
$this->cacheKeyPrefix = $cacheKeyPrefix; |
|
34
|
2 |
|
$this->hostname = gethostname() ?: ''; |
|
35
|
2 |
|
$this->pid = getmypid(); |
|
36
|
|
|
|
|
37
|
2 |
|
parent::__construct($runManager, $jobTimingManager, $jobClass); |
|
38
|
2 |
|
} |
|
39
|
|
|
|
|
40
|
|
|
public function setRedis(RedisInterface $redis) |
|
41
|
|
|
{ |
|
42
|
|
|
$this->redis = $redis; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
20 |
|
protected function getJobCacheKey($jobId) |
|
46
|
|
|
{ |
|
47
|
20 |
|
return $this->cacheKeyPrefix.'_job_'.$jobId; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param string $jobCrc |
|
52
|
|
|
*/ |
|
53
|
20 |
|
protected function getJobCrcHashKey($jobCrc) |
|
54
|
|
|
{ |
|
55
|
20 |
|
return $this->cacheKeyPrefix.'_job_crc_'.$jobCrc; |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
16 |
|
protected function getPriorityQueueCacheKey() |
|
59
|
|
|
{ |
|
60
|
16 |
|
return $this->cacheKeyPrefix.'_priority'; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
20 |
|
protected function getWhenQueueCacheKey() |
|
64
|
|
|
{ |
|
65
|
20 |
|
return $this->cacheKeyPrefix.'_when'; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
8 |
|
protected function getStatusCacheKey() |
|
69
|
|
|
{ |
|
70
|
8 |
|
return $this->cacheKeyPrefix.'_status'; |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|