saloonphp / saloon

🤠 Build beautiful API integrations and SDKs with Saloon
https://docs.saloon.dev
MIT License
2.03k stars 105 forks source link

Offloading a Listener for SentSaloonRequest events to a queue returns error #431

Closed denjaland closed 2 months ago

denjaland commented 2 months ago

We added an event listener that listens for SentSaloonRequest events to log all requests. This works fine as long as I don't have the listener implement ShouldQueue. As soon as we want to offload the logging of the request to the queue, we get an error Serialization of 'Closure' is not allowed

Is this a known issue? I have just setup some basic connector and a simple request by ID from an endpoint.

Sammyjo20 commented 2 months ago

Hey @denjaland thank you for letting me know about this, this is because the event contains closures which cannot be serialized, so sadly you wouldn't be able to implement the ShouldQueue interface onto your listener. You could handle the listener synchronously and fire off a queued job to process specific parts of the response e.g the body which could be quite easily serialised as an array or a string.

I also really appreciate the sponsor!

denjaland commented 2 months ago

Hi @Sammyjo20,

that is indeed the workaround I applied meanwhile. Are you having plans to get rid of the closures inside the event? Haven't dug into the code yet, but it would be really nice I believe :-)

Other than that I really like the package, so thanks for contributing to the community. I can't afford more atm, but always try to sponsor where I can, either by buying a paid product or though the sponsorship program here. So thanks again :-)

Sammyjo20 commented 2 months ago

Hey @denjaland

I don't have any immediate plans to change the way the response works, I think it's extremely useful that a response contains the pending request, request and connector from the request so you can easily trace it back, and unfortunately that means the middleware (which is closure-based) cannot be seralized. I will add it to my notes to see if this can be improved for v4.