Ruby on Rails - Decoupling Requests in Trailblazer Operations - ruby on rails tutorial - rails guides - rails tutorial - ruby rails
- Decoupling requests in trailblazer operation isn’t stateless, from an outer perspective, an operation is stateless because all you can do is operations.run.
- So, this makes it really simple to decouple front-end requests, as you can just send operations to a background worker without any work at all.
- Creating a profile needs thing like sending notifications, validating, and uploading the avatar photo, etc.
- In the Trailblazer framework, these parts will all be implemented in additional smaller operations.
- This makes it really simple to send several of the operations to a background job because the implementation of the operation doesn’t have to change, since they are already designed as a kind of background object.
- In my top-level operation, where the validation is finished and thus the profile data is all right, you have a chain of calling smaller operations.
- In that chain, you can decide where every operation goes (e.g. push this to the background job, push this to the background job, and wait for the result of this one.)
- Though, at the moment all of the operations you’ve had are fire and forget as you’ve never had one that you’d have to wait for, since the smaller operations in the background know how to update the application stage once they were run successfully.
- The thing is, modeling all my stuff in operations is a no-brainer…you just push it to a background job.
- For example, if you have an image sharing site where hundreds of thousands of photos are being uploaded and edited (and therefore there is a lot of domain logic going on), it will be much easier to reorder how those operations are run.