[Queues] Pending jobs in batches aren’t updated #59311
-
|
I've faced a problem while using
I noticed in this method that the job should have both Is this the expected behavior? Shouldn't it be: if (! in_array(Batchable::class, $uses) &&
! in_array(InteractsWithQueue::class, $uses)) {
return;
}framework/src/Illuminate/Queue/CallQueuedHandler.php Lines 197 to 200 in 2d8e8f4 Using InteractWithQueue in my job did fix the issue but it's either not in the docs, either a bug. |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
This is expected behavior, not a bug in the logic — but it's a real documentation gap. The actual condition in The code you quoted has protected function ensureSuccessfulBatchJobIsRecorded($command)
{
$uses = class_uses_recursive($command);
if (! in_array(Batchable::class, $uses) ||
! in_array(InteractsWithQueue::class, $uses) ||
is_null($command->batch())) {
return;
}
$command->batch()->recordSuccessfulJob($command->job->uuid());
}With Why Even if you changed $command->batch()->recordSuccessfulJob($command->job->uuid());
The fix Add use Illuminate\Bus\Batchable;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
class MyJob implements ShouldQueue
{
use Dispatchable, Queueable, Batchable, InteractsWithQueue;
public function handle(): void
{
// your logic
}
}On the docs gap You're right that this isn't spelled out clearly. The Laravel batching docs show |
Beta Was this translation helpful? Give feedback.
This is expected behavior, not a bug in the logic — but it's a real documentation gap.
The actual condition in
CallQueuedHandler.phpThe code you quoted has
&&, but the actual condition inensureSuccessfulBatchJobIsRecordeduses||:With
||, both traits are required — if either is absent, the method returns early andrecordSuccessfulJob()never fires.…