|
18 | 18 | use Hyperf\AsyncQueue\Event\QueueLength; |
19 | 19 | use Hyperf\AsyncQueue\Event\RetryHandle; |
20 | 20 | use Hyperf\AsyncQueue\MessageInterface; |
| 21 | +use Hyperf\AsyncQueue\Result; |
21 | 22 | use Hyperf\Codec\Packer\PhpSerializerPacker; |
22 | 23 | use Hyperf\Collection\Arr; |
23 | 24 | use Hyperf\Contract\PackerInterface; |
@@ -112,11 +113,22 @@ protected function getCallback($data, $message): callable |
112 | 113 | try { |
113 | 114 | if ($message instanceof MessageInterface) { |
114 | 115 | $this->event?->dispatch(new BeforeHandle($message)); |
115 | | - $message->job()->handle(); |
| 116 | + |
| 117 | + $result = $message->job()->handle(); |
| 118 | + |
| 119 | + match ($result) { |
| 120 | + Result::REQUEUE => $this->remove($data) && $this->retry($data), |
| 121 | + Result::RETRY => $this->remove($data) && $message->attempts() && $this->retry($message), |
| 122 | + Result::DROP => $this->remove($data), |
| 123 | + Result::ACK => $this->ack($data), |
| 124 | + default => $this->ack($data), |
| 125 | + }; |
| 126 | + |
116 | 127 | $this->event?->dispatch(new AfterHandle($message)); |
| 128 | + } else { |
| 129 | + // If the message is invalid, just ack it. |
| 130 | + $this->ack($data); |
117 | 131 | } |
118 | | - |
119 | | - $this->ack($data); |
120 | 132 | } catch (Throwable $ex) { |
121 | 133 | if (isset($message, $data)) { |
122 | 134 | if ($message->attempts() && $this->remove($data)) { |
|
0 commit comments