This is so much more easily solved by just sending the JSON document of the user in the message to the worker. A database look is not necessary, a transactional record lookup based on ID is overkill.
Rails, callbacks, workers, and the race you never expected to lose
21–28 of 28 posts
Re: Rails, callbacks, workers, and the race you never expected to lose
#22Re: Rails, callbacks, workers, and the race you never expected to lose
#23Earlier quoted context omitted.
He's not using the model to render the view, though, he's using it to queue up a future asynchronous request to the relevant mail "controller".
Sure, you're right, but only technically. Having an extra collaborator in the model is asking for trouble - there's nothing about a User that requires it to know anything about emailing. It violates all kinds of design principles. Putting your logic for "I should email the User when they sign up" into the User model is using "design by related words". In traditional Rails design, the controller is exactly the right p…
Anyway, I agree with pretty much everything you say. As I mentioned elsewhere in this thread, we've gone down a pub-sub event system for handling our generic post-action tasks. The controller announces a :create_user event, and any interested listeners can respond appropriately. And yes, one of the biggest benefits of this has been the ability to test that event-handling logic in isolation; stubbing and mocking collaborators, and generally having the sort of testing fun you're normally not supposed to have with Rails.
Re: Rails, callbacks, workers, and the race you never expected to lose
#24The DCI technique is to use the model as a persistence layer, and organize business logic into modules organized by use cases. With this technique my system has become much easier to understand and test.
Its great to see people experimenting with architecture styles like DCI and HexRails.
Re: Rails, callbacks, workers, and the race you never expected to lose
#25This is so much more easily solved by just sending the JSON document of the user in the message to the worker. A database look is not necessary, a transactional record lookup based on ID is overkill.
Maybe. We send different messages based on a user's subscription level which is two tables away ( user.account.subscription). I suppose we could dump that into the json object too, but IMO that just adds complexity.
Re: Rails, callbacks, workers, and the race you never expected to lose
#26This is so much more easily solved by just sending the JSON document of the user in the message to the worker. A database look is not necessary, a transactional record lookup based on ID is overkill.
Re: Rails, callbacks, workers, and the race you never expected to lose
#27Re: Rails, callbacks, workers, and the race you never expected to lose
#28Let me know if anyone is interested and I can share some code.