# Daily Jobs in Rails

**URL:** <https://www.ruby-forum.com/t/daily-jobs-in-rails/138417>\
**Category:** Rails\
**Created:** [May 22, 2008, 8:33pm UTC](https://www.ruby-forum.com/t/daily-jobs-in-rails/138417 "2008-05-22T20:33:11Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![chalkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8e7dd6/32.png) [@chalkers](https://www.ruby-forum.com/u/chalkers)\
**Post date:** [May 22, 2008, 8:33pm UTC](https://www.ruby-forum.com/t/daily-jobs-in-rails/138417/1 "2008-05-22T20:33:11Z")

</div>

Hi railers,

I have a quick question - I think it will be answered fairly easily  
methinks.

What’s the best practice (naming conventions, where to place in  
project etc) for creating a job to be ran every day?

For example - want to run a ruby script to grab an xml feed and  
persist it in a database.

Thanks

Andrew

---

<div class="post-metadata">

**Author:** ![chalkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8e7dd6/32.png) [@chalkers](https://www.ruby-forum.com/u/chalkers)\
**Post date:** [May 22, 2008, 8:36pm UTC](https://www.ruby-forum.com/t/daily-jobs-in-rails/138417/2 "2008-05-22T20:36:08Z")

</div>

On 5/22/08, chalkers [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> persist it in a database.  
> Put the job in the model. then run it with script/runner, via cron or  
> whatever.

script/runner -e production Foo.daily\_task

–  
Greg D.  
[http://destiney.com/](http://destiney.com/)

---

<div class="post-metadata">

**Author:** ![chalkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8e7dd6/32.png) [@chalkers](https://www.ruby-forum.com/u/chalkers)\
**Post date:** [May 22, 2008, 8:52pm UTC](https://www.ruby-forum.com/t/daily-jobs-in-rails/138417/3 "2008-05-22T20:52:36Z")

</div>

That’s bloody fantastic! Thank you.

---

<div class="post-metadata">

**Author:** ![chalkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8e7dd6/32.png) [@chalkers](https://www.ruby-forum.com/u/chalkers)\
**Post date:** [May 22, 2008, 9:26pm UTC](https://www.ruby-forum.com/t/daily-jobs-in-rails/138417/4 "2008-05-22T21:26:45Z")

</div>

You can find a couple alternative solutions here:

[http://groups.google.com/group/rubyonrails-talk/browse\_thread/thread/b6accea9d78d6e2e/6d29aadec26fbbd3?hl=en&lnk=gst&q=mcintyre#6d29aadec26fbbd3](http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/b6accea9d78d6e2e/6d29aadec26fbbd3?hl=en&lnk=gst&q=mcintyre#6d29aadec26fbbd3)

I suspect Andrew’s solution at the bottom of that post is probably  
best. Better than mine yes:-)

good luck!  
Tim

---

<div class="post-metadata">

**Author:** ![chalkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8e7dd6/32.png) [@chalkers](https://www.ruby-forum.com/u/chalkers)\
**Post date:** [May 22, 2008, 10:47pm UTC](https://www.ruby-forum.com/t/daily-jobs-in-rails/138417/5 "2008-05-22T22:47:27Z")

</div>

That seems a better alternative. Didn’t seem quite right in the model,  
and in the controller it’s a bit out of place. Tasks sounds like what  
the thing is. A task 🙂

---

<div class="post-metadata">

**Author:** ![chalkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8e7dd6/32.png) [@chalkers](https://www.ruby-forum.com/u/chalkers)\
**Post date:** [May 22, 2008, 10:43pm UTC](https://www.ruby-forum.com/t/daily-jobs-in-rails/138417/6 "2008-05-22T22:43:51Z")

</div>

Thanks Tim, that sounds a great alternative - putting things in tasks  
in tasks and actions in a controller! Simple, logical. Model was a bit  
out of place for what I needed.

---

<div class="post-metadata">

**Author:** ![chalkers](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/8e7dd6/32.png) [@chalkers](https://www.ruby-forum.com/u/chalkers)\
**Post date:** [May 22, 2008, 10:48pm UTC](https://www.ruby-forum.com/t/daily-jobs-in-rails/138417/7 "2008-05-22T22:48:03Z")

</div>

I think the point Andrew was making was to take the code out of the  
controller and put it in a task. As opposed to what the john was  
doing by having the code in a controller and calling it with curl.

I agree that the model doesn’t feel like a good place for this kind of  
thing:-)
