# Plugin for running a timer based application

**URL:** <https://www.ruby-forum.com/t/plugin-for-running-a-timer-based-application/174511>\
**Category:** Rails\
**Created:** [August 27, 2009, 9:59pm UTC](https://www.ruby-forum.com/t/plugin-for-running-a-timer-based-application/174511 "2009-08-27T21:59:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![rubala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a88e57/32.png) [@rubala](https://www.ruby-forum.com/u/rubala)\
**Post date:** [August 27, 2009, 9:59pm UTC](https://www.ruby-forum.com/t/plugin-for-running-a-timer-based-application/174511/1 "2009-08-27T21:59:10Z")

</div>

Hi,  
I am trying to achieve the following… wondering if there is any way to  
achieve this…

Some background:

1. i have an application where the user can request an specific email to  
be sent at a scheduled time. For e.g. lets say user A wants is  
scheudling the email to be sent for 12:00pm. This is stored in a table  
called “send\_notification” where the details is stored.
2. Another user B can login and schedule an notification say at 11:45am.

Now, to achieve this…  
Option 1:  
If can have a background task that scans through this table and sends  
the notification. But if i write it as a task that wakes up every minute  
and send the notification, then it has to scan the whole table every  
time. Is it OK ?. In a scaled table it could be an issue.  
Opton 2:  
Maintain a “earliest time” variable in the application. Every time, a  
new notification is created, check if this time is earlier than the  
“earliest time”. If so, then cancel the crontab and reschedule based on  
the “earliest time”. If not, the crontab will expire and notification  
will be sent and scan the whole table and update the “earliest time”.  
This again has the flaw of scanning the entire table.

Option 3:  
an efficient option is to maintain a heap timer tree based on “shcedule  
time”. Then the top node timer expires, the notification will be sent.  
This would require no scanning of table but maintaining the heap timer.  
Is a there a plugin for this ?.

How does typcially achieve such a thing.

Thanks.

---

<div class="post-metadata">

**Author:** ![rubala](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/a88e57/32.png) [@rubala](https://www.ruby-forum.com/u/rubala)\
**Post date:** [August 29, 2009, 2:03am UTC](https://www.ruby-forum.com/t/plugin-for-running-a-timer-based-application/174511/2 "2009-08-29T02:03:30Z")

</div>

Take a look at the Rufus Scheduler  
[http://rufus.rubyforge.org/rufus-scheduler/](http://rufus.rubyforge.org/rufus-scheduler/)

I hope this help you, regards.

Franco C…

On Aug 27, 4:59 pm, Rukku B. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
