Graychen /
yii2-queue-backend
This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace graychen\yii2\queue\backend\models; |
||
| 4 | |||
| 5 | use Yii; |
||
| 6 | use yii\base\Model; |
||
| 7 | use yii\di\Instance; |
||
| 8 | use yii\queue\serializers\PhpSerializer; |
||
| 9 | use yii\queue\serializers\Serializer; |
||
| 10 | |||
| 11 | /** |
||
| 12 | * Class RedisQueue |
||
| 13 | * @package graychen\yii2\queue\backend\models |
||
| 14 | * @property integer $total |
||
| 15 | * @property integer $done |
||
| 16 | * @property integer $waiting |
||
| 17 | * @property integer $delayed |
||
| 18 | * @property integer $reserved |
||
| 19 | */ |
||
| 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 | 6 | public function __construct(array $config = []) |
|
| 42 | { |
||
| 43 | 6 | $this->getPrefix(); |
|
| 44 | 6 | $this->serializer = Instance::ensure($this->serializer, PhpSerializer::class); |
|
| 45 | 6 | parent::__construct($config); |
|
| 46 | 6 | } |
|
| 47 | |||
| 48 | 6 | public function setPrefix() |
|
| 49 | { |
||
| 50 | 6 | $this->prefix = Yii::$app->queue->channel; |
|
| 51 | 6 | } |
|
| 52 | |||
| 53 | |||
| 54 | 6 | public function getPrefix() |
|
| 55 | { |
||
| 56 | 6 | $this->setPrefix(); |
|
| 57 | 6 | return $this->prefix; |
|
| 58 | } |
||
| 59 | |||
| 60 | 1 | public function setWaiting() |
|
| 61 | { |
||
| 62 | 1 | $this->waiting = Yii::$app->queue->redis->llen("$this->prefix.waiting"); |
|
| 63 | 1 | } |
|
| 64 | |||
| 65 | 1 | public function getWaiting() |
|
| 66 | { |
||
| 67 | 1 | $this->setWaiting(); |
|
| 68 | 1 | return $this->waiting; |
|
| 69 | } |
||
| 70 | |||
| 71 | 1 | public function setDelayed() |
|
| 72 | { |
||
| 73 | 1 | $this->delayed = Yii::$app->queue->redis->zcount("$this->prefix.delayed", '-inf', '+inf'); |
|
| 74 | 1 | } |
|
| 75 | |||
| 76 | 1 | public function getDelayed() |
|
| 77 | { |
||
| 78 | 1 | $this->setDelayed(); |
|
| 79 | 1 | return $this->delayed; |
|
| 80 | } |
||
| 81 | |||
| 82 | 1 | public function setReserved() |
|
| 83 | { |
||
| 84 | 1 | $this->reserved = Yii::$app->queue->redis->zcount("$this->prefix.reserved", '-inf', '+inf'); |
|
| 85 | 1 | } |
|
| 86 | |||
| 87 | 1 | public function getReserved() |
|
| 88 | { |
||
| 89 | 1 | $this->setReserved(); |
|
| 90 | 1 | return $this->reserved; |
|
| 91 | } |
||
| 92 | |||
| 93 | 1 | public function setTotal() |
|
| 94 | { |
||
| 95 | 1 | $this->total = Yii::$app->queue->redis->get("$this->prefix.message_id"); |
|
| 96 | 1 | } |
|
| 97 | |||
| 98 | 1 | public function getTotal() |
|
| 99 | { |
||
| 100 | 1 | $this->setTotal(); |
|
| 101 | 1 | return $this->total; |
|
| 102 | } |
||
| 103 | |||
| 104 | 1 | public function setDone() |
|
| 105 | { |
||
| 106 | 1 | $this->done = $this->total - $this->waiting - $this->delayed - $this->reserved; |
|
| 107 | 1 | } |
|
| 108 | |||
| 109 | 1 | public function getDone() |
|
| 110 | { |
||
| 111 | 1 | $this->setDone(); |
|
| 112 | 1 | return $this->done; |
|
| 113 | } |
||
| 114 | |||
| 115 | 1 | public function getWorkInfo() |
|
| 116 | { |
||
| 117 | 1 | $workers = []; |
|
| 118 | 1 | $data = Yii::$app->queue->redis->clientList(); |
|
| 119 | 1 | foreach (explode("\n", trim($data)) as $line) { |
|
| 120 | 1 | $client = []; |
|
| 121 | 1 | foreach (explode(' ', trim($line)) as $pair) { |
|
| 122 | 1 | list($key, $value) = explode('=', $pair, 2); |
|
| 123 | 1 | $client[$key] = $value; |
|
| 124 | } |
||
| 125 | |||
| 126 | 1 | if (isset($client['name']) && strpos($client['name'], Yii::$app->queue->channel . '.worker') === 0) { |
|
| 127 | 1 | $workers[$client['name']] = $client; |
|
| 128 | } |
||
| 129 | } |
||
| 130 | 1 | return $workers; |
|
| 131 | } |
||
| 132 | |||
| 133 | public function getWaitContent() |
||
| 134 | { |
||
| 135 | $waitContent = Yii::$app->queue->redis->lrange("$this->prefix.waiting", 0, 10); |
||
| 136 | return $waitContent; |
||
| 137 | } |
||
| 138 | |||
| 139 | public function getReservedContent() |
||
| 140 | { |
||
| 141 | return Yii::$app->queue->redis->zrange("$this->prefix.reserved", 0, -1); |
||
| 142 | } |
||
| 143 | |||
| 144 | public function getDelayedContent() |
||
| 145 | { |
||
| 146 | return Yii::$app->queue->redis->zrange("$this->prefix.delayed", 0, -1); |
||
| 147 | } |
||
| 148 | |||
| 149 | 1 | public function getMessage($id) |
|
| 150 | { |
||
| 151 | 1 | $message = Yii::$app->queue->redis->hget("$this->prefix.messages", $id); |
|
| 152 | 1 | $strMessage = ltrim($message, '300;'); |
|
| 153 | 1 | return $this->serializer->unserialize($strMessage); |
|
| 154 | } |
||
| 155 | |||
| 156 | public function getAttempt($id) |
||
| 157 | { |
||
| 158 | $attempt = Yii::$app->queue->redis->hget("$this->prefix.attempt", $id); |
||
| 159 | $strAttempt = ltrim($attempt, '300;'); |
||
| 160 | return $this->serializer->unserialize($strAttempt); |
||
| 161 | } |
||
| 162 | |||
| 163 | |||
| 164 | /** 得到执行时间 |
||
| 165 | * @param $id todo |
||
| 166 | */ |
||
| 167 | public function getExecutionTime($id) |
||
|
0 ignored issues
–
show
|
|||
| 168 | { |
||
| 169 | } |
||
| 170 | |||
| 171 | /** 得到队列的状态 |
||
| 172 | * @param $id |
||
| 173 | * @return int |
||
| 174 | */ |
||
| 175 | 1 | public function status($id) |
|
| 176 | { |
||
| 177 | 1 | if (Yii::$app->queue->redis->hexists("$this->prefix.attempts", $id)) { |
|
| 178 | return self::STATUS_RESERVED; |
||
| 179 | 1 | } elseif (Yii::$app->queue->redis->hexists("$this->prefix.messages", $id)) { |
|
| 180 | 1 | return self::STATUS_WAITING; |
|
| 181 | } else { |
||
| 182 | return self::STATUS_DONE; |
||
| 183 | } |
||
| 184 | } |
||
| 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.