forked from laravel/framework
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInteropJob.php
94 lines (79 loc) · 2.06 KB
/
InteropJob.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<?php
namespace Illuminate\Queue\Jobs;
use Illuminate\Container\Container;
use Illuminate\Contracts\Queue\Job as JobContract;
use Interop\Queue\PsrConsumer;
use Interop\Queue\PsrContext;
use Interop\Queue\PsrMessage;
class InteropJob extends Job implements JobContract
{
/**
* @var PsrContext
*/
private $psrContext;
/**
* @var PsrConsumer
*/
private $psrConsumer;
/**
* @var PsrMessage
*/
private $psrMessage;
/**
* @param Container $container
* @param PsrContext $psrContext
* @param PsrConsumer $psrConsumer
* @param PsrMessage $psrMessage
* @param string $connectionName
*/
public function __construct(Container $container, PsrContext $psrContext, PsrConsumer $psrConsumer, PsrMessage $psrMessage, $connectionName)
{
$this->container = $container;
$this->psrContext = $psrContext;
$this->psrConsumer = $psrConsumer;
$this->psrMessage = $psrMessage;
$this->connectionName = $connectionName;
}
/**
* {@inheritdoc}
*/
public function delete()
{
parent::delete();
$this->psrConsumer->acknowledge($this->psrMessage);
}
/**
* {@inheritdoc}
*/
public function release($delay = 0)
{
if ($delay) {
throw new \LogicException('To be implemented');
}
$requeueMessage = clone $this->psrMessage;
$requeueMessage->setProperty('x-attempts', $this->attempts() + 1);
$this->psrContext->createProducer()->send($this->psrConsumer->getQueue(), $requeueMessage);
$this->psrConsumer->acknowledge($this->psrMessage);
}
/**
* {@inheritdoc}
*/
public function getQueue()
{
return $this->psrConsumer->getQueue()->getQueueName();
}
/**
* {@inheritdoc}
*/
public function attempts()
{
return $this->psrMessage->getProperty('x-attempts', 1);
}
/**
* {@inheritdoc}
*/
public function getRawBody()
{
return $this->psrMessage->getBody();
}
}