Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

jbot's avatar
Level 1

What is the recommended way to handle job class renames?

Scenario:

  1. Create class JobA
  2. Deploy application
  3. Enqueue JobA with delay
  4. Rename JobA to JobB
  5. Deploy application
  6. 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)
  • ...?

What is the recommended way?

0 likes
3 replies
bobbybouwmann's avatar
Level 88

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 ;)

jbot's avatar
Level 1

@BOBBYBOUWMANN - Thanks for the reply!

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 :)

bobbybouwmann's avatar

Not really by default. You could come up with some system that handles this, but it sounds way to much work fo what you really need!

Please or to participate in this conversation.