1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ccovey\LaravelRabbitMQ; |
4
|
|
|
|
5
|
|
|
use Ccovey\RabbitMQ\Consumer\ConsumerInterface; |
6
|
|
|
use Ccovey\RabbitMQ\Producer\Message; |
7
|
|
|
use Ccovey\RabbitMQ\Producer\ProducerInterface; |
8
|
|
|
use Ccovey\RabbitMQ\QueuedMessage; |
9
|
|
|
use DateTime; |
10
|
|
|
use Illuminate\Contracts\Container\Container; |
11
|
|
|
use Illuminate\Contracts\Queue\Job as JobContract; |
12
|
|
|
use Illuminate\Queue\Jobs\Job; |
13
|
|
|
|
14
|
|
|
class RabbitMqJob extends Job implements JobContract |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* @var Container |
18
|
|
|
*/ |
19
|
|
|
protected $container; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var ProducerInterface |
23
|
|
|
*/ |
24
|
|
|
private $producer; |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* @var ConsumerInterface |
28
|
|
|
*/ |
29
|
|
|
private $consumer; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var QueuedMessage |
33
|
|
|
*/ |
34
|
|
|
private $message; |
35
|
|
|
|
36
|
|
|
public function __construct(Container $container, ProducerInterface $producer, ConsumerInterface $consumer, QueuedMessage $message) |
37
|
|
|
{ |
38
|
|
|
$this->container = $container; |
39
|
|
|
$this->producer = $producer; |
40
|
|
|
$this->consumer = $consumer; |
41
|
|
|
$this->message = $message; |
42
|
|
|
$this->queue = $this->message->getQueueName(); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get the number of times the job has been attempted. |
47
|
|
|
* |
48
|
|
|
* @return int |
49
|
|
|
*/ |
50
|
|
|
public function attempts() |
51
|
|
|
{ |
52
|
|
|
return $this->message->attempts ?? 0; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Get the raw body string for the job. |
57
|
|
|
* |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public function getRawBody() |
61
|
|
|
{ |
62
|
|
|
return $this->message->getRawBody(); |
|
|
|
|
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function delete() |
66
|
|
|
{ |
67
|
|
|
parent::delete(); |
68
|
|
|
$this->consumer->getChannel()->acknowledge($this->message->getDeliveryTag()); |
|
|
|
|
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function release($delay = 0) |
72
|
|
|
{ |
73
|
|
|
parent::release($delay); |
74
|
|
|
$body = $this->message->getBody(); |
75
|
|
|
|
76
|
|
|
if ($delay > 0) { |
77
|
|
|
$body['scheduledAt'] = new DateTime(sprintf('+%s', $delay)); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
$body['attempts'] = isset($body['attempts']) ? $body['attempts'] + 1 : 1; |
81
|
|
|
$message = new Message($body, $this->message->getQueueName()); |
82
|
|
|
|
83
|
|
|
$this->producer->publish($message); |
84
|
|
|
$this->consumer->getChannel()->acknowledge($this->message->getDeliveryTag()); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
} |
87
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.