Plugins - background
Add to favoritesThis Rails plugin lets you execute arbitrary Ruby blocks in a background process. In comparison to existing background processing frameworks, this plugin has many advantages:
- Responsibilities don't get cut out of objects (most of the time, the code running in the background process actually belongs to an object residing in the foreground process). This can be solved by delegating the time-consuming task to the background process, which clones the object, and delegates the task back to it, only in another process.
- It's DRY. Background processes tend to repeat code, like the above mentioned back-delegation. This can be reduced to a certain extent, but there will always be some overhead.
- It's Failsafe. Almost always, the task at hand is delegated over a socket of some sort. If the other process is busy, hangs or is down, there can be timeouts which result in ugly exceptions, and in the end, discard the task. To make background processing failsafe, you need to write a lot more code, which is repetitive as well.
Running a task in the background is as easy as
background do # run your code end
The communication with the background process is configurable, as is the error handling. For example, you could use ActiveMQ for queueing your background tasks. If the connection to ActiveMQ fails for some reason, the task could be executed in-process. If this fails (e.g. because of an error or timeout), the task would be dumped to disk for a later replay when the problem is fixed.
http://opensource.imedo.de/pages/show/background
git://github.com/imedo/background.git
Rails' (MIT)
Misc. Enhancements
