Skip to content

Commit

Permalink
Merge pull request #27 from laravel/revert-26-pr17289
Browse files Browse the repository at this point in the history
Revert "Use ApproximateReceiveCount to find job attempts"
  • Loading branch information
themsaid authored Feb 4, 2020
2 parents f67927c + 099790f commit 66e9978
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/Queue/VaporJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,39 @@

class VaporJob extends SqsJob
{
//
/**
* Release the job back into the queue.
*
* @param int $delay
* @return void
*/
public function release($delay = 0)
{
$this->released = true;

$payload = $this->payload();

$payload['attempts']++;

$this->sqs->deleteMessage([
'QueueUrl' => $this->queue,
'ReceiptHandle' => $this->job['ReceiptHandle'],
]);

$this->sqs->sendMessage([
'QueueUrl' => $this->queue,
'MessageBody' => json_encode($payload),
'DelaySeconds' => $this->secondsUntil($delay),
]);
}

/**
* Get the number of times the job has been attempted.
*
* @return int
*/
public function attempts()
{
return ($this->payload()['attempts'] ?? null) + 1;
}
}
21 changes: 21 additions & 0 deletions src/Queue/VaporQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@

class VaporQueue extends SqsQueue
{
/**
* Pop the next job off of the queue.
*
* @param string $queue
* @return \Illuminate\Contracts\Queue\Job|null
*/
public function pop($queue = null)
{
$response = $this->sqs->receiveMessage([
'QueueUrl' => $queue = $this->getQueue($queue),
'AttributeNames' => ['ApproximateReceiveCount'],
]);

if (! is_null($response['Messages']) && count($response['Messages']) > 0) {
return new VaporJob(
$this->container, $this->sqs, $response['Messages'][0],
$this->connectionName, $queue
);
}
}

/**
* Create a payload string from the given job and data.
*
Expand Down

0 comments on commit 66e9978

Please sign in to comment.