How to cancel a queued job in Laravel or Redis

How do I view all pending jobs in my Redis queue so that I can cancel Mailable that has a specific pair of EmailAddress-sendTime pairs?

I am using Laravel 5.5 and have Mailable, which I successfully use as follows:

$sendTime = Carbon::now()->addHours(3); Mail::to($emailAddress) ->bcc([config('mail.supportTeam.address'), config('mail.main.address')]) ->later($sendTime, new MyCustomMailable($subject, $dataForMailView)); 

When this code runs, the job is added to my Redis queue.

I have already read the Laravel docs , but remain confused.

How can I cancel Mailable (prevent it from being sent)?

I would like to encode the webpage in my Laravel application, which makes this easy for me.

Or maybe there are tools that already make it easy (maybe FastoRedis?)? In this case, instructions on how to achieve this goal will also be helpful. Thanks!

Update:

I tried to view the Redis queue using FastoRedis, but I can’t figure out how to remove Mailable, for example, the red arrow points to this: enter image description here

+5
source share
5 answers

hope this helps

 $connection = null; $default = 'default'; //For the delayed jobs var_dump( \Queue::getRedis()->connection($connection)->zrange('queues:'.$default.':delayed' ,0, -1) ); //For the reserved jobs var_dump( \Queue::getRedis()->connection($connection)->zrange('queues:'.$default.':reserved' ,0, -1) ); 

$connection is the name of the Redis connection, which is null by default, and $queue is the name of the queue / pipe, which is the default!

source: fooobar.com/questions/1001665 / ...

+1
source

I installed the new application on my server and installed (on my own subdomain) this web interface for managing my Redis: https://github.com/ErikDubbelboer/phpRedisAdmin

This allows me to edit or delete the keys and ZSet values ​​that appear to be queued in Larvel delayed Mailables.

Another approach that worked for me was to install Redis Desktop Manager on my Windows PC.

I think I prefer phpRedisAdmin, since I will have access to it from the Internet (using any device).

+1
source

One approach may be to check the operation to determine if a specific address / time has been set for cancellation (removed from the queue). Set up the database table or save the value permanently with the address / time in the array. Then, in your handle method, check to see if something is marked for deletion and compare it with the mailing address / processing time:

 public function handle() { if (Cache::has('items_to_remove')) { $items = Cache::get('items_to_remove'); $removed = null; foreach ($items as $item) { if ($this->mail->to === $item['to'] && $this->mail->sendTime === $item['sendTime']) { $removed = $item; $this->delete(); break; } } if (!is_null($removed)) { $diff = array_diff($items, $removed); Cache::set(['items_to_remove' => $diff]); } } } 
+1
source

Perhaps, instead of canceling it, you can actually delete it from Redis, from what Ive read from the official documents about the command to forget in Redis and from the Laravel white paper that interacts with redis , you can basically call any Redis command from of the interface, if you could call the forget command and actually go node_id , which in this case I think is the number that you have in your image DEL 1517797158 I think you could achieve "cancellation".

+1
source

Make it easier.

Do not send an email with a later version. You must submit a task with a later version, and this task will be responsible for sending the email.

Inside this job, check the emailAddress-sendTime pair before sending an email. If this is correct, send an email; if not, return true and the email will not be sent and the job will end.

+1
source

Source: https://habr.com/ru/post/1274703/


All Articles