Skip to content

Commit 58259b2

Browse files
author
Ivan Borzenkov
committed
Illegal string offset 'attempts'
1 parent 07bad84 commit 58259b2

File tree

2 files changed

+23
-50
lines changed

2 files changed

+23
-50
lines changed

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

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,10 @@ public function release($delay = 0)
8282
$attempts = $this->attempts();
8383

8484
// write attempts to body
85-
$body['data']['attempts'] = $attempts + 1;
85+
$body['attempts'] = $attempts + 1;
8686

87-
$job = $body['job'];
88-
$data = $body['data'];
89-
90-
// push back to a queue
91-
if ($delay > 0) {
92-
$this->connection->later($delay, $job, $data, $this->getQueue());
93-
} else {
94-
$this->connection->push($job, $data, $this->getQueue());
95-
}
87+
$this->connection->pushRaw(json_encode($body), $this->getQueue(),
88+
$delay > 0 ? [ 'delay' => $delay ] : []);
9689
}
9790

9891
/**
@@ -104,7 +97,7 @@ public function attempts()
10497
{
10598
$body = json_decode($this->message->body, true);
10699

107-
return isset($body['data']['attempts']) ? $body['data']['attempts'] : 0;
100+
return isset($body['attempts']) ? $body['attempts'] : 0;
108101
}
109102

110103
/**

src/FintechFab/LaravelQueueRabbitMQ/Queue/RabbitMQQueue.php

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -44,69 +44,49 @@ public function __construct(AMQPConnection $amqpConnection, $config)
4444
*/
4545
public function push($job, $data = '', $queue = null)
4646
{
47-
$queue = $this->getQueueName($queue);
48-
$payload = $this->createPayload($job, $data);
49-
$this->declareQueue($queue);
50-
51-
// push job to a queue
52-
$message = new AMQPMessage($payload, [
53-
'Content-Type' => 'application/json',
54-
'delivery_mode' => 2,
55-
]);
56-
57-
$this->channel->basic_publish($message, $queue, $queue);
58-
59-
return true;
47+
return $this->pushRaw($this->createPayload($job, $data), $queue, []);
6048
}
6149

6250
/**
63-
* Push a raw payload onto the queue.
51+
* Push a new job onto the queue after a delay.
6452
*
65-
* @param string $payload
66-
* @param string $queue
67-
* @param array $options
53+
* @param \DateTime|int $delay
54+
* @param string $job
55+
* @param mixed $data
56+
* @param string $queue
6857
*
6958
* @return mixed
7059
*/
71-
public function pushRaw($payload, $queue = null, array $options = [])
60+
public function later($delay, $job, $data = '', $queue = null)
7261
{
73-
$queue = $this->getQueueName($queue);
74-
$this->declareQueue($queue);
75-
76-
// push job to a queue
77-
$message = new AMQPMessage($payload, [
78-
'Content-Type' => 'application/json',
79-
'delivery_mode' => 2,
80-
]);
81-
82-
// push task to a queue
83-
$this->channel->basic_publish($message, $queue, $queue);
84-
85-
return true;
62+
return $this->pushRaw($this->createPayload($job, $data), $queue, ['delay' => $delay]);
8663
}
8764

8865
/**
89-
* Push a new job onto the queue after a delay.
66+
* Push a raw payload onto the queue.
9067
*
91-
* @param \DateTime|int $delay
92-
* @param string $job
93-
* @param mixed $data
94-
* @param string $queue
68+
* @param string $payload
69+
* @param string $queue
70+
* @param array $options
9571
*
9672
* @return mixed
9773
*/
98-
public function later($delay, $job, $data = '', $queue = null)
74+
public function pushRaw($payload, $queue = null, array $options = [])
9975
{
100-
$payload = $this->createPayload($job, $data);
76+
$queue = $this->getQueueName($queue);
10177
$this->declareQueue($queue);
102-
$queue = $this->declareDelayedQueue($queue, $delay);
78+
if (isset($options['delay']))
79+
{
80+
$queue = $this->declareDelayedQueue($queue, $options['delay']);
81+
}
10382

10483
// push job to a queue
10584
$message = new AMQPMessage($payload, [
10685
'Content-Type' => 'application/json',
10786
'delivery_mode' => 2,
10887
]);
10988

89+
// push task to a queue
11090
$this->channel->basic_publish($message, $queue, $queue);
11191

11292
return true;

0 commit comments

Comments
 (0)