What is the recommended way to handle job class renames?
Scenario:
Create class JobA
Deploy application
Enqueue JobA with delay
Rename JobA to JobB
Deploy application
Queue worker throws Method __PHP_Incomplete_Class::handle() does not exist error, because there is still a job in queue with old name JobA
Some thoughts about possible solutions:
Copy job class with new name instead of renaming, then remove old class after some time? Seems easiest, though not convenient (people can just forget to do this).
Wait until queue is empty? Not suitable because of possible job delays.
Detect renames during deployment and requeue jobs with new names? Sounds weird, requires interface breaking: adding methods to find jobs by name (which contradicts the jobs queue principle, AFAIK) or introspecting queue driver and working with jobs directly
Use permanent job identifier instead of class name? Requires framework modification (at least Queue component)
Well I think you should ask yourself the question first if you're going to do this often or not. If this happens once a year I wouldn't bother too much and just copy the class with a new name and check if they queue is empty with the old tasks and remove it later on. You might even already remove it on the next release as an example.
Another option would be catching all the failed jobs and requeuing them by hand with the correct job now. You can use php artisan tinker for that if you wish, but this means you need to know what you're doing.
All the other options requires lots of changes and structural changes to the framework and how queues currently work as well. So it just depends on how much times you will have to do this.
Personally I would just copy it and wait until there is no job anymore and delete it from the codebase. You can simple set a reminder in your agenda for over 2 months and do the check then ;)
Job renames/removals are the rare case, so I'll probably stick to the copy way. Even if I'll forget it, I can easily requeue failed jobs manually via Tinker as I did before, it's not a big deal.
I just thought there is a "right" way in Laravel to handle such situations :)