How do you handle recurring tasks

i have several tasks which i need to be executed from time to time …
some every 20 minutes and some only 1 time a day … you know things like
e.g. clearing old sessions, deleting inactive users …

how do you deal with stuff like this? cronjobs? how is your pattern for
such things … thanks in advance

On 12/27/07, Michal G. [email protected]
wrote:

i have several tasks which i need to be executed from time to time …
some every 20 minutes and some only 1 time a day … you know things like
e.g. clearing old sessions, deleting inactive users …

how do you deal with stuff like this? cronjobs? how is your pattern for
such things … thanks in advance

http://groups.google.com/group/rubyonrails-talk/browse_thread/thread/2d316fa75d15d03e/2f9ff335c5880f87


Greg D.
http://destiney.com/

thanks greg … this helps me to solve my problems …

I too have the same issue. Can someone comment on using script/runner
via a cronjob vs. using the backgroundrb method described above?

Thank you,
Jim

If you need to schedule recurring tasks that are related with a ruby on
rails application you are building then you should go with the
backgroundrb plugin for rails. You can easily schedule tasks but the
best part is that the tasks will have full access to the rails
environment.

It really depends on what you guys are trying to do. I know that is said
alot but it is true. There are certain jobs where a cron job might be
the best (simple jobs such as clearing the session, removing cruft,
simple system stuff)

Script/runner is simple but it is nice because it is built into rails.
The runner script simply loads the rails environment and then executes
some simple ruby code (either a simple ruby statement or a filename).
On the plus side, it is the simplest choice. Some downsides are that
multiple versions of the script might be running side by side which
needs to be accounted for or could be pretty harmful (backgroundrb
queues up tasks by default).

there are certain jobs where backgroundrb daemons are the best choice
(jobs where you are performing actions requiring access to the rails
environment, models, library, etc) and also passing parameters or
wanting tasks to queue up, etc.

Tell me what you want to do and I can try to help recommend the best
course of action.

JimCifarelli wrote:

I too have the same issue. Can someone comment on using script/runner
via a cronjob vs. using the backgroundrb method described above?

Thank you,
Jim

yep i would appreciate this information too…

On 12/27/07, Michal G. [email protected]
wrote:

  • i want to get rid of unused sessions

class ApplicationController < ActionController::Base

before_filter :clean

def clean
ActiveRecord::Base.connection.execute( "
DELETE FROM sessions
WHERE NOW() - updated_at > 3600
" ) if rand( 1000 ) % 10 == 0
end

end


Greg D.
http://destiney.com/

thanks for the quick comparison … what i want to achieve is the
following

  • i want to get rid of unused sessions
  • delete records of several tables where one column indicates that the
    record has expired
  • last but not least those tasks should be configurable within my
    application (e.g. which task to execute when) if possible

Nathan E. wrote:

It really depends on what you guys are trying to do. I know that is said
alot but it is true. There are certain jobs where a cron job might be
the best (simple jobs such as clearing the session, removing cruft,
simple system stuff)

Script/runner is simple but it is nice because it is built into rails.
The runner script simply loads the rails environment and then executes
some simple ruby code (either a simple ruby statement or a filename).
On the plus side, it is the simplest choice. Some downsides are that
multiple versions of the script might be running side by side which
needs to be accounted for or could be pretty harmful (backgroundrb
queues up tasks by default).

there are certain jobs where backgroundrb daemons are the best choice
(jobs where you are performing actions requiring access to the rails
environment, models, library, etc) and also passing parameters or
wanting tasks to queue up, etc.

Tell me what you want to do and I can try to help recommend the best
course of action.

very interesting approach … but something like this i would rather use
for smaller projects.

Greg D. wrote:

class ApplicationController < ActionController::Base

before_filter :clean

def clean
ActiveRecord::Base.connection.execute( "
DELETE FROM sessions
WHERE NOW() - updated_at > 3600
" ) if rand( 1000 ) % 10 == 0
end

end

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs