Creating Daemon Thread in Rails

Would anyone know where I could find a tutorial on how to create a
background daemon ruby thread in rails?

Moses

Try looking at the Process module (or maybe it’s a class?) , and the
Daemons gem.

Or if you could clarify exactly what you need I could try to help
more.

I want to create a task or thread running in the background monitoring
an entry within a database table within ruby and comparing this entry
with the current time. If the current time is greater than a limit.
The task will report an alert to the specified user by email.

Moses

One way to do this is just to create a ruby script which includes the
rails environment, loads the record using active record, and sends an
email using active mailer. Then have cron run that script
periodically.

Hi Moses,

mmccall wrote:

Would anyone know where I could find a tutorial
on how to create a background daemon ruby thread
in rails?

Not sure if this is what you’re looking for, but you might want to take
a
look at BackgroundRb.

HTH,
Bill

[email protected] wrote:

One way to do this is just to create a ruby script which includes the
rails environment, loads the record using active record, and sends an
email using active mailer. Then have cron run that script
periodically.

This is probably the best way to go. You don’t really need to do your
own polling daemon, it seems. Just make sure that you’re only running
the cron every so often, otherwise the startup time of the Rails
environment will be significant compared to your execution time.

Hi,

One way to do this is just to create a ruby script which includes the
rails environment, loads the record using active record, and sends an
email using active mailer. Then have cron run that script
periodically.

This is probably the best way to go.
You could do this pretty neatly by using rake. You only need to create a
task and then use rake for invoking it. In your case you could do it by
hand or via cron. If you include ‘environment’ as a dependency for your
task, then your rails environment will be loaded for you and you can
access your models as usual. It’s easy, it’s clean, it’s descriptive as
it will be listed under rake -T and it’s easy to launch from the command
line.

If for any reason you prefer a script and not a task (not sure why you’d
actually want it), then you don’t need to care about how to load the
enviroment or whatever. You can invoke any script with script/runner and
the rails boot-up sequence will be executed before calling your script,
so you can also here access your models as always.

regards,

javier ramirez

Thanks