4

For example : When I want to update product I create job for that and I put job into queue. Job is waiting there and it is still not processed, In meantime I need to create new job for update the same product but with different data and now I want to remove old update job from queue and push new one to queue, any ideas ?

1
  • Did you try pop() method? pop(string $queue = null) Commented Jul 19, 2018 at 13:34

1 Answer 1

1

I had an idea. On every job dispatch you would set a cache key, this uuid would also be set on the job's properties.

$uuid = uuid();
Redis::set("update-product-token-$ID",$uuid);
$data['uuid'] = $uuid;
ProductUpdateJob::dispatch($data);

On the first line of the handle function, you check if the redis token matches the job's token. If they don't the job exits gracefully

$uuid = Redis::get("update-product-token-$ID",NULL);
if($uuid !== NULL && $uuid !== $this->uuid) return;
//proceed with update here

No querying the queue, no guessing, no halting an update mid execution. Elegant stuff. Let me know what you think.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.