# Howto get stuff to happen automatically?

**URL:** <https://www.ruby-forum.com/t/howto-get-stuff-to-happen-automatically/126066>\
**Category:** Rails\
**Created:** [January 15, 2008, 5:13am UTC](https://www.ruby-forum.com/t/howto-get-stuff-to-happen-automatically/126066 "2008-01-15T05:13:14Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [January 15, 2008, 5:13am UTC](https://www.ruby-forum.com/t/howto-get-stuff-to-happen-automatically/126066/1 "2008-01-15T05:13:14Z")

</div>

I’m trying to get certain emails sent at a certain datetime.  
So I have a column in my table called “due\_by”, as soon as it’s overdue  
is it possible to get an automatic email notification?

How do people get stuff like this to happen via. Rails without user  
interaction?

TIA  
Luke

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [January 15, 2008, 5:49am UTC](https://www.ruby-forum.com/t/howto-get-stuff-to-happen-automatically/126066/2 "2008-01-15T05:49:47Z")

</div>

You would need some sort of script that queues your table for any  
email notifications that are due. An easy way to do this with your AR  
models is to make a rake task which checks for any items due and sends  
them.

You could have this run every 5 minutes or so using a cron job.

A more advanced solution might offload this to an external queue which  
your script could poll from in an infinite loop.

Just some ideas…

On Jan 14, 8:13 pm, Luke G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [January 15, 2008, 5:55am UTC](https://www.ruby-forum.com/t/howto-get-stuff-to-happen-automatically/126066/3 "2008-01-15T05:55:53Z")

</div>

Hmm, yeah I thought about just making it a cronjob, but I’m not too sure  
if an external infinite loop is a good idea…

Is a cronjob the most common method of getting it done? or is there  
something else that everyone uses?

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [January 15, 2008, 5:59am UTC](https://www.ruby-forum.com/t/howto-get-stuff-to-happen-automatically/126066/4 "2008-01-15T05:59:42Z")

</div>

backgroundrb lets you schedule ruby tasks like cronjobs.

On Jan 15, 2008 3:25 PM, Luke G.  
[removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> >

–  
Ryan B.

> **[frozenplague.net](http://www.frozenplague.net)**
>
> This domain may be for sale!

Feel free to add me to MSN and/or GTalk as this email.

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [January 15, 2008, 6:11am UTC](https://www.ruby-forum.com/t/howto-get-stuff-to-happen-automatically/126066/5 "2008-01-15T06:11:23Z")

</div>

It doesn’t have to be a cron job. You can just have your app run an  
infinite loop e.g.:

loop do

# script code

end

and then manage this script with god. It’d be more responsive this  
way.

On Jan 14, 8:55 pm, Luke G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [January 16, 2008, 10:07pm UTC](https://www.ruby-forum.com/t/howto-get-stuff-to-happen-automatically/126066/6 "2008-01-16T22:07:43Z")

</div>

"A more advanced solution might offload this to an external queue  
which  
your script could poll from in an infinite loop. "

How would that effect your local database?

On Jan 14, 9:23 pm, Luke G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![galeal](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/8c91f0/32.png) [@galeal](https://www.ruby-forum.com/u/galeal)\
**Post date:** [January 15, 2008, 6:23am UTC](https://www.ruby-forum.com/t/howto-get-stuff-to-happen-automatically/126066/7 "2008-01-15T06:23:52Z")

</div>

A loop like that would have serious performance implications on the  
server if it’s hitting the database, checking a couple of values and  
sending emails each trip wouldn’t it?

Oh, btw Ryan, cheers for backgroundrb, that looks good. I might use  
that.

eggie5 wrote:

> It doesn’t have to be a cron job. You can just have your app run an  
> infinite loop e.g.:
> 
> loop do
> 
> # script code
> 
> end
> 
> and then manage this script with god. It’d be more responsive this  
> way.
> 
> On Jan 14, 8:55 pm, Luke G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
