Backgroundrb - workers firing twice?

I’ve got backgroundrb handling three periodic tasks. For some reason,
each of them is firing twice on each run. From my backgroundrb.log:

Daily stats in production at Sat Nov 04 03:00:41 EST 2006
Daily stats in production at Sat Nov 04 03:00:41 EST 2006
11 expired sessions being deleted at Sat Nov 04 03:03:41 EST 2006
0 expired sessions being deleted at Sat Nov 04 03:03:41 EST 2006
Database backup in production at Sat Nov 04 03:33:41 EST 2006
Database backup in production at Sat Nov 04 03:33:41 EST 2006

You get the idea.

Each of the workers has some variation of the following:

MINUTES_TO_KEEP = 15
repeat_every MINUTES_TO_KEEP.minutes
first_run Time.now

My backgroundrb.yml config file has:

autostart:
1:
job_key: session_cleanup1
class: session_cleanup_worker
2:
job_key: database_backup1
class: database_backup_worker
3:
job_key: log_statistics
class: daily_stats_worker

Does anybody have an idea why this is happening, and what I can do to
stop it?

–Al Evans

Al Evans wrote:

Does anybody have an idea why this is happening, and what I can do to
stop it?

I didn’t figure out why this was happening, but here’s a workaround in
case anybody else runs into the same problem:

LOCK_NAME = “#{RAILS_ROOT}/log/whatever.lock”

def lock_file
return false if File.exists?(LOCK_NAME)
f = File.open(LOCK_NAME, “w”)
f.close
true
end

def clear_lock_file
File.delete(LOCK_NAME)
end

def do_work(args)
if lock_file

clear_lock_file
end
end

–Al Evans–

I have a very similar setup and I can confirm behavior. Not sure why the
workers fire twice. Here’s a solution that doesn’t rely upon files:

@@running=false

def do_work(args)
if not @@running
@@running=true

@@running=false
end
end

Chris S. wrote:

I have a very similar setup and I can confirm behavior. Not sure why the
workers fire twice. Here’s a solution that doesn’t rely upon files:

@@running=false

def do_work(args)
if not @@running
@@running=true

@@running=false
end
end

Thanks Chris it’s really a very good solution.

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