Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Batchable doesn't work properly without InteractsWithQueue trait #50057

Closed
rahimi-ali opened this issue Feb 12, 2024 · 2 comments
Closed

Batchable doesn't work properly without InteractsWithQueue trait #50057

rahimi-ali opened this issue Feb 12, 2024 · 2 comments

Comments

@rahimi-ali
Copy link

rahimi-ali commented Feb 12, 2024

Laravel Version

10.43.0

PHP Version

8.2.10

Database Driver & Version

No response

Description

As far as I know it is possible to have working jobs without using the InteractsWithQueue trait but when using the job batching functionality using Bus::batch and Batchable trait this is required for the batch to work properly.

When the InteractsWithQueue trait is not present on the job class the batch will never be considered as finished. I believe this is due to the if statement in the ensureSuccessfulBatchJobIsRecorded method on CallQueuedHandler class which returns early if either the job class does not use the Batchable trait or the InteractsWithQueue trait. I'm not quite sure why this is.

I think one of these solutions should be implemented:

  1. Use the InteractsWithQueue trait in the Batchable trait itself so it is guaranteed that it will work.
  2. If the if statement in ensureSuccessfulBatchJobIsRecorded is somehow not needed it can be removed and then it should work. I am not too sure about this because I couldn't find any uses of the methods available on the InteractsWithQueue trait used in Batchable trait or the Illuminate\Bus\Batch class but I might not have looked in the right places.
  3. Explicitly Mention this requirement in the documentation.

I am interesed in contributing to this issue but not quite sure which of these solutions or any other solution is prefered by the maintainers.

Steps To Reproduce

class SampleBatchableJob implements Illuminate\Contracts\Queue\ShouldQueue
{
    use Illuminate\Bus\Queueable;
    use Illuminate\Foundation\Bus\Dispatchable;
    use Illuminate\Bus\Batchable;
    
    public function handle() {}    
}

Illuminate\Support\Facades\Bus::batch([
    new SampleBatchableJob,
    new SampleBatchableJob
])->dispatch();

// after the jobs are processed `pending_jobs` will remain 2 and `finished_at` will remain null in the `job_batches` table.
Copy link

Thank you for reporting this issue!

As Laravel is an open source project, we rely on the community to help us diagnose and fix issues as it is not possible to research and fix every issue reported to us via GitHub.

If possible, please make a pull request fixing the issue you have described, along with corresponding tests. All pull requests are promptly reviewed by the Laravel team.

Thank you!

@driesvints
Copy link
Member

Looks like we're not going to make any changes here right now sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants