1 | <?php |
||
20 | class RedisQueue extends Model |
||
21 | { |
||
22 | /** |
||
23 | * @see Queue::isWaiting() |
||
24 | */ |
||
25 | const STATUS_WAITING = 1; |
||
26 | /** |
||
27 | * @see Queue::isReserved() |
||
28 | */ |
||
29 | const STATUS_RESERVED = 2; |
||
30 | /** |
||
31 | * @see Queue::isDone() |
||
32 | */ |
||
33 | const STATUS_DONE = 3; |
||
34 | /** |
||
35 | * @var Serializer|array |
||
36 | */ |
||
37 | public $serializer = PhpSerializer::class; |
||
38 | |||
39 | public $prefix; |
||
40 | |||
41 | 5 | public function __construct(array $config = []) |
|
42 | { |
||
43 | 5 | $this->getPrefix(); |
|
44 | 5 | $this->serializer = Instance::ensure($this->serializer, Serializer::class); |
|
45 | parent::__construct($config); |
||
46 | } |
||
47 | |||
48 | 5 | public function setPrefix() |
|
52 | |||
53 | |||
54 | 5 | public function getPrefix() |
|
59 | |||
60 | public function setWaiting() |
||
64 | |||
65 | public function getWaiting() |
||
70 | |||
71 | public function setDelayed() |
||
75 | |||
76 | public function getDelayed() |
||
81 | |||
82 | public function setReserved() |
||
86 | |||
87 | public function getReserved() |
||
92 | |||
93 | public function setTotal() |
||
94 | { |
||
95 | $this->total = Yii::$app->queue->redis->get("$this->prefix.message_id"); |
||
96 | } |
||
97 | |||
98 | public function getTotal() |
||
99 | { |
||
100 | $this->setTotal(); |
||
101 | return $this->total; |
||
102 | } |
||
103 | |||
104 | public function setDone() |
||
105 | { |
||
106 | $this->done = $this->total - $this->waiting - $this->delayed - $this->reserved; |
||
107 | } |
||
108 | |||
109 | public function getDone() |
||
110 | { |
||
111 | $this->setDone(); |
||
112 | return $this->done; |
||
113 | } |
||
114 | |||
115 | public function getWorkInfo() |
||
116 | { |
||
117 | $workers = []; |
||
118 | $data = Yii::$app->queue->redis->clientList(); |
||
119 | foreach (explode("\n", trim($data)) as $line) { |
||
120 | $client = []; |
||
121 | foreach (explode(' ', trim($line)) as $pair) { |
||
122 | list($key, $value) = explode('=', $pair, 2); |
||
123 | $client[$key] = $value; |
||
124 | } |
||
125 | |||
126 | if (isset($client['name']) && strpos($client['name'], Yii::$app->queue->channel . '.worker') === 0) { |
||
127 | $workers[$client['name']] = $client; |
||
128 | } |
||
129 | } |
||
130 | return $workers; |
||
131 | } |
||
132 | |||
133 | public function getWaitContent() |
||
138 | |||
139 | public function getReservedContent() |
||
143 | |||
144 | public function getDelayedContent() |
||
148 | |||
149 | public function getMessage($id) |
||
150 | { |
||
151 | $message = Yii::$app->queue->redis->hget("$this->prefix.messages", $id); |
||
152 | $strMessage = ltrim($message, '300;'); |
||
153 | return $this->serializer->unserialize($strMessage); |
||
154 | } |
||
155 | |||
156 | public function getAttempt($id) |
||
162 | |||
163 | |||
164 | /** 得到执行时间 |
||
165 | * @param $id todo |
||
166 | */ |
||
167 | public function getExecutionTime($id) |
||
170 | |||
171 | /** 得到队列的状态 |
||
172 | * @param $id |
||
173 | * @return int |
||
174 | */ |
||
175 | public function status($id) |
||
176 | { |
||
177 | if (Yii::$app->queue->redis->hexists("$this->prefix.attempts", $id)) { |
||
185 | } |
||
186 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.