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

Closure in job chain is not called if preceded by job batch #51897

Open
eldair opened this issue Jun 24, 2024 · 2 comments
Open

Closure in job chain is not called if preceded by job batch #51897

eldair opened this issue Jun 24, 2024 · 2 comments

Comments

@eldair
Copy link

eldair commented Jun 24, 2024

Laravel Version

11.11.1

PHP Version

8.3.8

Database Driver & Version

No response

Description

Closure in job Bus::chain is not called if it is after Bus::batch - exception is thrown but there is nothing in failed jobs.
Call to undefined method Closure::getClosure() {"exception":"[object] (Error(code: 0): Call to undefined method Closure::getClosure() at /home/eldair/code/bus_chain_test/vendor/laravel/framework/src/Illuminate/Queue/CallQueuedClosure.php:107)

Steps To Reproduce

Batch setup

$batch = [];
for ($i=0; $i < 5; $i++) {
    $batch[] = new BatchJob($i + 1);
}

This will throw the exception and the closure will not be called

Bus::chain([
    new ChainedJob,
    Bus::batch($batch),
    function () {
        logger('after batch');
    }
])->dispatch();

This works fine

Bus::chain([
    new ChainedJob,
    Bus::batch($batch),
    new ChainedJob,
    function () {
        logger('after batch');
    }
])->dispatch();

Here is the reproduction repo https://github.com/eldair/bus_chain_test/tree/main, nothing was added except two jobs and console command to call the code above.

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!

@Dry7
Copy link

Dry7 commented Jun 30, 2024

In my opinion, the problem is that the serializable-closure library incorrectly handles the case when SerializableClosure is used as a property type inside another SerializableClosure.

This case is happening here

$batch->finally(function (Batch $batch) use ($next) {

I fixed the issue in this pull request laravel/serializable-closure#86

I think this bug will be fixed when my pull request is accepted

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