Question

My website is hosted on AWS Elastic Beanstalk (PHP). I use Yii Framework as an MVC.

A while ago I wanted to run a SQL query everyday. I looked up how to run crons on Beanstalk and it seemed complicated to merge the concepts of Cloud and Cron. I ran into Iron Worker (http://www.iron.io/worker), and managed to create a worker that is currently doing its job fine.

Today I want to run a more complex cron (Look for notifications in my database, decide whether to send an email, build an email template and send the email (via AWS SES).

From what I understand, worker files are supposed to be self-contained items, with everything they need to work. However, I have invested a lot of time and effort in building my MVC. I have complex models, verifications, an email templating engine, etc... It seems very difficult to use the work I've done to create an Iron Worker. Even if I managed to port all of my code to a worker (which seems like a great deal of work), it means anytime I make changes to my main code I need to make sure the worker also has those changes. It means I would have a "branch" of my code. Even more so if I want to create more workers in the future.

What is the correct approach?

Was it helpful?

Solution

Short-term, you could likely just use the scheduling capabilities in IronWorker and have the worker hit an endpoint in your application. The endpoint will then trigger the operations to run within your app environment.

Longer-term, we do suggest you look at more of a service-oriented approach whereby you break your application up to be more loose-coupled and distributed. Here's a post on the subject. The advantages are many especially around scalability and development agility.

https://blog.heroku.com/archives/2013/12/3/end_monolithic_app

You can also take a look at this YII addition.

http://www.yiiframework.com/extension/yiiron/

Certainly don't want you rewrite your app unnecessarily but there are likely areas where you can look to decouple. Suggest creating a worker directory and making efforts to write the workers to be self-contained. In that way, you could run them in a different environment and just pass payloads to the worker. (Push queues can also be used to push to these workers.) Once you get used to distributed async processing, it's a pretty easy process to manage.

(Note: I work at Iron.io)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top