ariaby
ariaby

Reputation: 902

Delete a queue job outside of a worker in Laravel 4?

I understand the listener passes a Job instance to my worker and i can use that instance to delete the job, but how can i delete a job outside of worker? Consider this scenario:

$job_id=Queue::push('DoTheJob', array('data'=>array(1,2,3)));

If(!someotherjobdone){
// delete job from Queue  with job_id
?
}

Thank you

Upvotes: 4

Views: 724

Answers (2)

eaykin
eaykin

Reputation: 3813

In my case, I am implementing SQS Queue. If I have the 'ReceiptHandle' of the message (an ID associated with a specific instance of receiving the message), I can delete it by accessing the SqsClient object through the SQSManager, because the manager is accessible by the IoC container.

$queue_manager = App::make("queue");
$sqs_queue = $queue_manager->connection('sqs');
$sqs_client = $sqs_queue->getSqs(); 
$sqs_client->deleteMessage(['QueueUrl' => $queue_url, 'ReceiptHandle' => $receipt_handle]);

Upvotes: 0

Beau
Beau

Reputation: 1771

I'm not certain if this is correct, but I think you want to 'pop' the job off the queue:

$job_id=Queue::push('DoTheJob', array('data'=>array(1,2,3)));

If(!someotherjobdone){
    Queue::pop($job_id);
}

If that doesn't work you could try:

$queue=Queue::getQueue($job_id);
Queue::pop($queue);

Upvotes: 1

Related Questions