Dne pondělí, 8. července 2013 0:42:59 UTC+2 Ilya Grigorik napsal(a):
I've seen them. I am actually using this pattern right now. For example, one of the reasons why there is AMQP dependency is to offload things like sending email to the external process / worker.Typical example would be:
- user changes setting through UI
- UI is actually independent web application talking to my Goliath service through some API
- when the API endpoint is hit
- data are updated in PostgreSQL through ActiveRecord model
- there is additional logic in the model, e.g. it emmits a message to AMQP queue to send user an email with confirmation of change
- logic can be sometimes complex and involves multiple other models
I need to write a worker which will invoke certain methods regurarly. For example it will be looking for expired user's subscriptions and send the users an email. I already have majority of logic in existing AR model, I can send emails through AMQP messages. I can make a service API endpoint and then call it with curl from cron and execute job within the main process or use the EM.add_timer. But that it a bit smelly. Therefore I would like to use other process to run these workers but reuse the AR and other infrastructure I already have.
So really something like rails runner to be able to execute script within the context of the environment. That was the reason I was talking about reusing Goliath::Console.run!()
Thank you,
Antonin