# Background task with rake...or better solution?

**URL:** <https://www.ruby-forum.com/t/background-task-with-rake-or-better-solution/181999>\
**Category:** Rails\
**Created:** [January 21, 2010, 10:33am UTC](https://www.ruby-forum.com/t/background-task-with-rake-or-better-solution/181999 "2010-01-21T10:33:39Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 21, 2010, 10:33am UTC](https://www.ruby-forum.com/t/background-task-with-rake-or-better-solution/181999/1 "2010-01-21T10:33:39Z")

</div>

Hello everybody,  
my new customer wants the new application that stay out of his way. To  
make it short he wants to drop images in a folder, and the app should  
be so clever to find them, make thumnails and other resized files and  
serve them as soon as possible on the backend. I plan to create a  
button that start the process and he will have to push it, he’s  
methodical but still human, so at times he will probably forget to do  
it. To avoid furious phone calls from him I’d like to create an  
automated task that will do this job every let’s say 2-3 minutes, so  
data will be always served fresh anyway. Is a rake task associated  
with a cron job the right way to go? I’ve never had such a strange  
requirement, so I can’t think of anything better right now. Any  
suggestion will be highly appreciated.  
Thanks

JJ Smith

---

<div class="post-metadata">

**Author:** ![captaffy](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/f04885/32.png) [@captaffy](https://www.ruby-forum.com/u/captaffy)\
**Post date:** [January 21, 2010, 4:10pm UTC](https://www.ruby-forum.com/t/background-task-with-rake-or-better-solution/181999/2 "2010-01-21T16:10:49Z")

</div>

Quoting John S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> with a cron job the right way to go? I’ve never had such a strange  
> requirement, so I can’t think of anything better right now. Any  
> suggestion will be highly appreciated.  
> Thanks

Or a cronjob that uses script/runner to call the Rails code to do it.  
Or  
any of the background processors with any scheduled task ability. Or if  
pure  
Ruby code will do it (i.e., no Rails environment needed), call Ruby  
script  
from cron.

Startup CPU costs are substantial with Rails. If the production server  
has  
lots of free memory, use a Ruby or Rails program that processes, sleeps  
for  
2-3 minutes, and processes again. In my experience (my) Rails programs  
have  
small memory leaks and so I let the script run for an hour, then exit.  
Cron  
starts a new copy every hour. One advantage is that if the script is  
changed,  
the new version will start being used within the hour. As the system  
matures,  
I may stretch it out to restarting once a day instead of once an hour.

There are many ways to do it. I suppose you could use the FAM daemon to  
notice the new file and start the processing. Don’t know what kind of  
hooks  
are available to/from Ruby/Rails code.

HTH,  
Jeffrey
