|
4 | 4 |
|
5 | 5 | use Illuminate\Container\Container; |
6 | 6 | use Illuminate\Contracts\Container\BindingResolutionException; |
| 7 | +use Illuminate\Contracts\Encryption\Encrypter; |
7 | 8 | use Illuminate\Contracts\Queue\Job as JobContract; |
8 | 9 | use Illuminate\Queue\Jobs\Job; |
9 | 10 | use Illuminate\Support\Arr; |
10 | 11 | use PhpAmqpLib\Exception\AMQPProtocolChannelException; |
11 | 12 | use PhpAmqpLib\Message\AMQPMessage; |
12 | 13 | use PhpAmqpLib\Wire\AMQPTable; |
| 14 | +use Salesmessage\LibRabbitMQ\Contracts\RabbitMQConsumable; |
13 | 15 | use Salesmessage\LibRabbitMQ\Horizon\RabbitMQQueue as HorizonRabbitMQQueue; |
14 | 16 | use Salesmessage\LibRabbitMQ\Queue\RabbitMQQueue; |
15 | 17 |
|
@@ -126,15 +128,53 @@ public function release($delay = 0): void |
126 | 128 | { |
127 | 129 | parent::release(); |
128 | 130 |
|
| 131 | + $consumableJob = $this->getPayloadData(); |
| 132 | + if (!($consumableJob instanceof RabbitMQConsumable)) { |
| 133 | + throw new \RuntimeException('Job must be an instance of RabbitMQJobBatchable'); |
| 134 | + } |
| 135 | + |
129 | 136 | // Always create a new message when this Job is released |
130 | | - $this->rabbitmq->laterRaw($delay, $this->message->getBody(), $this->queue, $this->attempts()); |
| 137 | + $this->rabbitmq->laterRaw($delay, $this->message->getBody(), $this->queue, $this->attempts(), $consumableJob->getQueueType()); |
131 | 138 |
|
132 | 139 | // Releasing a Job means the message was failed to process. |
133 | 140 | // Because this Job message is always recreated and pushed as new message, this Job message is correctly handled. |
134 | 141 | // We must tell rabbitMQ this job message can be removed by acknowledging the message. |
135 | 142 | $this->rabbitmq->ack($this); |
136 | 143 | } |
137 | 144 |
|
| 145 | + /** |
| 146 | + * @return object |
| 147 | + * @throws \RuntimeException |
| 148 | + */ |
| 149 | + public function getPayloadData(): object |
| 150 | + { |
| 151 | + $payload = $this->payload(); |
| 152 | + |
| 153 | + $data = $payload['data']; |
| 154 | + |
| 155 | + if (str_starts_with($data['command'], 'O:')) { |
| 156 | + return unserialize($data['command']); |
| 157 | + } |
| 158 | + |
| 159 | + if ($this->container->bound(Encrypter::class)) { |
| 160 | + return unserialize($this->container[Encrypter::class]->decrypt($data['command'])); |
| 161 | + } |
| 162 | + |
| 163 | + throw new \RuntimeException('Unable to extract job data.'); |
| 164 | + } |
| 165 | + |
| 166 | + /** |
| 167 | + * Returns target class name |
| 168 | + * |
| 169 | + * @return mixed |
| 170 | + */ |
| 171 | + public function getPayloadClass(): string |
| 172 | + { |
| 173 | + $payload = $this->payload(); |
| 174 | + |
| 175 | + return $payload['data']['commandName']; |
| 176 | + } |
| 177 | + |
138 | 178 | /** |
139 | 179 | * Get the underlying RabbitMQ connection. |
140 | 180 | */ |
|
0 commit comments