How can I browse all the pending jobs within my Redis queue so that I could cancel the Mailable that has a certain emailAddress-sendTime pair?
I'm using Laravel 5.5 and have a Mailable that I'm using successfully 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, a job gets added to my Redis queue.
I've already read the Laravel docs but remain confused.
How can I cancel a Mailable (prevent it from sending)?
I'd love to code a webpage within my Laravel app that makes this easy for me.
Or maybe there are tools that already make this easy (maybe FastoRedis?)? In that case, instructions about how to achieve this goal that way would also be really helpful. Thanks!
Update:
I've tried browsing the Redis queue using FastoRedis, but I can't figure out how to delete a Mailable, such as the red arrow points to here:
UPDATE:
Look at the comprehensive answer I provided below.
Make it easier.
Don't send an email with the later option. You must dispatch a Job with the later option, and this job will be responsible to send the email.
Inside this job, before send the email, check the emailAddress-sendTime pair. If is correct, send the email, if not, return true and the email won't send and the job will finish.
Removing all queued jobs:
Maybe instead of canceling it you can actually remove it from the Redis, from what Ive read from official docs about forget command on Redis and from Laravel official doc interacting with redis you can basically call any
Redis
command from the interface, if you could call theforget
command and actually passnode_id
which in this case I think it's that number you have in your imageDEL 1517797158
I think you could achieve the "cancel".hope this helps
$connection
is the Redis connection name which is null by default, and The$queue
is the name of the queue / tube which is 'default' by default!source : https://stackoverflow.com/a/42182586/6109499
New, Comprehensive Answer:
I now use my own custom DispatchableWithControl trait instead of the Dispatchable trait.
I call it like this:
So, now I can look in my 'automations' table to see pending jobs, and I can delete (or soft-delete) any of those records if I want to prevent the job from executing.
Old Answer:
I set up a new app on my server and installed (on its own subdomain) this web interface for managing my Redis: https://github.com/ErikDubbelboer/phpRedisAdmin
It allows me to edit or delete ZSet keys and values, which seems to be how Laravel delayed Mailables get saved to the queue.
Another approach that worked for me was to install Redis Desktop Manager on my Windows PC.
I think I'll prefer phpRedisAdmin since I'll be able to access it from the web (using any device).
One approach may be to have your job check to see if you've set a specific address/time to be canceled (deleted from queue). Setup a database table or cache a value forever with the address/time in an array. Then in your job's
handle
method check if anything has been marked for removal and compare it to the mailable's address/time it is processing: