spiral-modules / jobs

RoadRunner: Background PHP workers, Queue brokers
MIT License
60 stars 11 forks source link

[Feature Request] Allow passing objects into jobs #21

Closed myavchik closed 4 years ago

myavchik commented 4 years ago

Allow passing objects into jobs

$queue->push(new SomeJob([
                'user' => $user // User object
            ]));

---------------------------

class SomeJob extends AbstractJob
{
    public function do(User $user)
wolfy-j commented 4 years ago

Hi,

you are looking at 1.0 API which has been using Laravel style. Take a look at 2.0 described in documentations.

You are still not able to pass objects directly due to conceptual limitations (for example, what PHP User should do in Golang handler?), but you have two clear methods responsible for hydration/extraction of data so you can pack this object into any form you want. https://github.com/spiral/docs/blob/feature/2.0/queue/jobs.md#managing-payloads

myavchik commented 4 years ago

Oh... thanks.

wolfy-j commented 4 years ago

This feature is exactly the reason why we abandon such jobs design as it becomes impossible to implement rich payload management without a massive amount of magic.

wolfy-j commented 4 years ago