[SOLVED] Job Queue call deferred methods in Job itself

I’m currently re-implementing our asynchronous background jobs using the Job Queue package.
In general it’s working like a charm but I have one scenario where it doesn’t seem to work (guess I’m just doing something wrong ;-))
I have a function that is called deferred. This function itself calls other functions in the same class that should be called deferred as well.
The functions that are called don’t return anything, are public and have the @Job\Defer annotation but they seem to be executed right away without creating an entry in the corresponding MySQL table (Job Queue Doctrine package).
I tried if it makes a difference if I don’t use $this->myFunction(); but rather inject the class and call $this->myClass->myFunction(); but the subsequent function calls still seem to be executed synchronously.

Is this supposed to work in general? If so do you guys have any idea what could be the problem?

Thanks to @aberl in Slack I know that this is the problem the job queue doesn’t allow recursion.
Still need to find a way to solve that :wink:

This is a protection against having endless loops with recursion from jobs. I’m not fully sure if it’s really needed, so maybe we could remove this protection in the aspect.

But anyway, there’s a workaround by not using the Defer annotation:

        $job = new StaticMethodCallJob(MyClass::class, 'myMethod', [$arg0, $arg1]);
        $this->jobManager->queue($queueName, $job);

That’s basically everything the aspect does.

Hi Christopher,

thank you! That’s pretty much what I ended up doing and it works like a charm.
I also tried to build my own aspect without the check for recursion and noticed very fast that there’s a reason for it :wink:
If you remove that the aspect ends up creating new jobs in an endless loop since it never get’s to execute the actual function.

Well, that was the case then :wink: