I am using the Openwferu scheduler in a Rails application.
It is currently being started from environment.rb.
I run the application using Mongrel-cluster.
Because this uses 3 different processes I get 3 schedulers and 3 x the
actions scheduled.
I don't know much about threads,
but is it possible to have only the first mongrel process startup the
scheduler?
Or is there another way of doing this?
I know this is more an Ruby / Rails question, but I am a bit lost
here.
I've looked into other schedulers but they don't work for me.
Hi,
I don't know anything about Mongrel-cluster.
1). you could dig Mongrel-cluster documentation to see if there is a
way to communicate between the clustered instances and prevent
instances other than instance 0 from using the Scheduler.
2). you could use an empty 'semaphore' file. Each instance would not
start the scheduler if the file exists else it will immediately create
(touch) the file and the start the scheduler.
3). maybe there is a way for your instances to know that they are
instances in a cluster and maybe there is a way for them to know "yes,
I'm the first instance", "no, I'm not the first instance" and behave
accordingly.
4). avoid all of that but putting the scheduling logic outside of any
instance, maybe with code started once, alongside the Mongrel-cluster.
I hope this will help, best regards,
--
John Mettraux -///- http://jmettraux.openwfe.org
For others figuring out this problem, this is what I use now:
##########################################
require 'fileutils'
require 'openwfe/util/scheduler'
include OpenWFE
semaphore = RAILS_ROOT + '/tmp/scheduler'
if File.exist?(semaphore)
logger.warn "scheduler already started"
else
begin
logger.warn "starting scheduler #{ Time.now }"
scheduler = Scheduler.new
scheduler.start
scheduler.schedule_every('4h') do
# do something
end
FileUtils.touch(semaphore)
rescue Exception => ex
logger.warn ex
end
end
##########################################
Very simple, but aren't all answers?
Thx again John!
On Jul 25, 4:26 pm, "John Mettraux" <jmettr...@openwfe.org> wrote:
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "OpenWFEru users" group.
To post to this group, send email to openwfe...@googlegroups.com
To unsubscribe from this group, send email to openwferu-users-unsubscribe @googlegroups.com
For more options, visit this group at http://groups.google.com/group/openwferu-users?hl=en
-~----------~----~----~----~-- ----~----~------~--~---
# part of my capistrano2 config-file
###############################################
desc "Run this before the restart"
before "deploy:restart", :remove_semaphore
desc "Removing semaphore file to start the scheduler"
task :remove_semaphore do
semaphore = "#{ release_path }/tmp/scheduler"
sudo "rm -f #{semaphore}"
end
###############################################
On Jul 26, 2:45 pm, "Lee Fyock" <lee.fy...@gmail.com> wrote:
> How do you know when to delete the semaphore file, so that you can shut down
> the server, start it up, and have the scheduler run again?
> Where did you place this code? In environment.rb (or a file that gets called
> from environment.rb)?
>
> Thanks,
> Lee
>
no, not from environment.rb .
I want to have the scheduler inside my Rails application.
I could run it using script/runner but then I have to maintain another
process.
This way the scheduler is stopped when I stop the application and vice-
versa.
On Jul 26, 3:55 pm, "Lee Fyock" <lee.fy...@gmail.com> wrote:
> You could run it from environment.rb, though, since your semaphore file
> takes care of multiple app instances running the scheduler. That's the whole
> point, right? :-)
> I'm not very familiar with capistrano. Is it responsible for launching your
> application as well? If so, couldn't you skip the whole semaphore thing and
> have capistrano start and stop the scheduler, rather than an application
> instance starting the scheduler?
>
> Thanks,
> Lee
>
> On 7/26/07, Dachtutn...@gmail.com <Dachtutn...@gmail.com> wrote:
>
>
>
> > no, not from environment.rb.
On Jul 26, 4:40 pm, "Lee Fyock" <lee.fy...@gmail.com> wrote:
> So, where inside your application do you start the scheduler? Inside
> application.rb?
> In case you can't tell from my questions, we have a similar configuration
> (multiple mongrel instances) and I'm thinking of using OpenWFEru for some
> periodic tasks.
>
> Thanks!
> Lee
>
Cheers
Anselmo