1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Ccovey\LaravelRabbitMQ; |
4
|
|
|
|
5
|
|
|
use Ccovey\RabbitMQ\Producer\Message; |
6
|
|
|
use Ccovey\RabbitMQ\Producer\Producer; |
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 QueuedMessage |
28
|
|
|
*/ |
29
|
|
|
private $message; |
30
|
|
|
|
31
|
|
|
public function __construct(Container $container, ProducerInterface $producer, QueuedMessage $message) |
32
|
|
|
{ |
33
|
|
|
$this->container = $container; |
34
|
|
|
$this->producer = $producer; |
35
|
|
|
$this->message = $message; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* Get the number of times the job has been attempted. |
40
|
|
|
* |
41
|
|
|
* @return int |
42
|
|
|
*/ |
43
|
|
|
public function attempts() |
44
|
|
|
{ |
45
|
|
|
return $this->message->attempts ?? 0; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Get the raw body string for the job. |
50
|
|
|
* |
51
|
|
|
* @return string |
52
|
|
|
*/ |
53
|
|
|
public function getRawBody() |
54
|
|
|
{ |
55
|
|
|
$this->message->getRawBody(); |
|
|
|
|
56
|
|
|
} |
57
|
|
|
|
58
|
|
|
public function delete() |
59
|
|
|
{ |
60
|
|
|
parent::delete(); |
61
|
|
|
$this->producer->getChannel()->acknowledge($this->message->delivery_tag); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function release($delay = 0) |
65
|
|
|
{ |
66
|
|
|
parent::release($delay); |
67
|
|
|
$body = $this->message->getBody(); |
68
|
|
|
|
69
|
|
|
if ($delay > 0) { |
70
|
|
|
$body['scheduledAt'] = new DateTime(sprintf('+%s', $delay)); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
$body['attempts'] = isset($body['attempts']) ? $body['attempts'] + 1 : 1; |
74
|
|
|
$message = new Message($body, $this->message->getQueueName()); |
75
|
|
|
|
76
|
|
|
$this->producer->publish($message); |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|
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.