Skip to content

Commit fc93808

Browse files
committed
making changes provided by @ivan1986 in branch 4.2
1 parent 4ee6c37 commit fc93808

File tree

2 files changed

+12
-31
lines changed

2 files changed

+12
-31
lines changed

src/FintechFab/LaravelQueueRabbitMQ/Queue/Jobs/RabbitMQJob.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php namespace FintechFab\LaravelQueueRabbitMQ\Queue\Jobs;
22

3+
use FintechFab\LaravelQueueRabbitMQ\Queue\RabbitMQQueue;
34
use Illuminate\Container\Container;
45
use Illuminate\Contracts\Queue\Job as JobContract;
56
use Illuminate\Queue\Jobs\Job;
@@ -10,18 +11,21 @@
1011
class RabbitMQJob extends Job implements JobContract
1112
{
1213

14+
protected $connection;
1315
protected $channel;
1416
protected $queue;
1517
protected $message;
1618

1719
public function __construct(
1820
Container $container,
21+
RabbitMQQueue $connection,
1922
AMQPChannel $channel,
2023
$queue,
2124
AMQPMessage $message
2225
)
2326
{
2427
$this->container = $container;
28+
$this->connection = $connection;
2529
$this->channel = $channel;
2630
$this->queue = $queue;
2731
$this->message = $message;
@@ -91,11 +95,10 @@ public function release($delay = 0)
9195
$job = $body['job'];
9296
$data = $body['data'];
9397

94-
// push back to a queue
9598
if ($delay > 0) {
96-
Queue::later($delay, $job, $data, $this->getQueue());
99+
$this->connection->later($delay, $job, $data, $this->getQueue());
97100
} else {
98-
Queue::push($job, $data, $this->getQueue());
101+
$this->connection->push($job, $data, $this->getQueue());
99102
}
100103
}
101104

src/FintechFab/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php

Lines changed: 6 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use FintechFab\LaravelQueueRabbitMQ\Queue\Jobs\RabbitMQJob;
55
use Illuminate\Contracts\Queue\Queue as QueueContract;
66
use Illuminate\Queue\Queue;
7-
use Illuminate\Queue\QueueInterface;
87
use PhpAmqpLib\Channel\AMQPChannel;
98
use PhpAmqpLib\Connection\AMQPConnection;
109
use PhpAmqpLib\Message\AMQPMessage;
@@ -45,19 +44,7 @@ public function __construct(AMQPConnection $amqpConnection, $config)
4544
*/
4645
public function push($job, $data = '', $queue = null)
4746
{
48-
$queue = $this->getQueueName($queue);
49-
$payload = $this->createPayload($job, $data);
50-
$this->declareQueue($queue);
51-
52-
// push job to a queue
53-
$message = new AMQPMessage($payload, [
54-
'Content-Type' => 'application/json',
55-
'delivery_mode' => 2,
56-
]);
57-
58-
$this->channel->basic_publish($message, $queue, $queue);
59-
60-
return true;
47+
return $this->pushRaw($this->createPayload($job, $data), $queue, []);
6148
}
6249

6350
/**
@@ -73,6 +60,9 @@ public function pushRaw($payload, $queue = null, array $options = [])
7360
{
7461
$queue = $this->getQueueName($queue);
7562
$this->declareQueue($queue);
63+
if (isset($options['delay'])) {
64+
$queue = $this->declareDelayedQueue($queue, $options['delay']);
65+
}
7666

7767
// push job to a queue
7868
$message = new AMQPMessage($payload, [
@@ -98,19 +88,7 @@ public function pushRaw($payload, $queue = null, array $options = [])
9888
*/
9989
public function later($delay, $job, $data = '', $queue = null)
10090
{
101-
$payload = $this->createPayload($job, $data);
102-
$this->declareQueue($queue);
103-
$queue = $this->declareDelayedQueue($queue, $delay);
104-
105-
// push job to a queue
106-
$message = new AMQPMessage($payload, [
107-
'Content-Type' => 'application/json',
108-
'delivery_mode' => 2,
109-
]);
110-
111-
$this->channel->basic_publish($message, $queue, $queue);
112-
113-
return true;
91+
return $this->pushRaw($this->createPayload($job, $data), $queue, ['delay' => $delay]);
11492
}
11593

11694
/**
@@ -131,7 +109,7 @@ public function pop($queue = null)
131109
$message = $this->channel->basic_get($queue);
132110

133111
if ($message instanceof AMQPMessage) {
134-
return new RabbitMQJob($this->container, $this->channel, $queue, $message);
112+
return new RabbitMQJob($this->container, $this, $this->channel, $queue, $message);
135113
}
136114

137115
return null;

0 commit comments

Comments
 (0)