Scott Ward
2008-Jan-28 19:32 UTC
[Backgroundrb-devel] Scheduling same worker/method at different times with different args
I need to run the same worker''s method twice per day with different arguments. Unfortunately, only the second entry in the schedule is firing. I created an experimental worker to verify this: Worker: class ExperimentWorker < BackgrounDRb::MetaWorker set_worker_name :experiment_worker def create(args = nil) # this method is called, when worker is loaded for the first time end def experiment(args = {}) logger.info "#{Time.now} - Experiment fired at #{args[:repeat_second]} second mark." end end In backgroundrb.yml: :schedules: :experiment_worker: :experiment: :trigger_args: "0 * * * * * *" :data: :repeat_second: zero :experiment: :trigger_args: "30 * * * * * *" :data: :repeat_second: thirty In the log, I only see "Experiment fired at thirty second mark." Why isn''t the first entry for experiment worker firing? Perhaps, I have this set up wrong? Thanks, Scott
hemant
2008-Jan-28 20:15 UTC
[Backgroundrb-devel] Scheduling same worker/method at different times with different args
On Tue, Jan 29, 2008 at 1:02 AM, Scott Ward <scott at shefield.com> wrote:> I need to run the same worker''s method twice per day with different > arguments. Unfortunately, only the second entry in the schedule is firing. > > I created an experimental worker to verify this: > > Worker: > class ExperimentWorker < BackgrounDRb::MetaWorker > set_worker_name :experiment_worker > def create(args = nil) > # this method is called, when worker is loaded for the first time > end > > def experiment(args = {}) > logger.info "#{Time.now} - Experiment fired at #{args[:repeat_second]} > second mark." > end > end > > > In backgroundrb.yml: > :schedules: > :experiment_worker: > :experiment: > :trigger_args: "0 * * * * * *" > :data: > :repeat_second: zero > :experiment: > :trigger_args: "30 * * * * * *" > :data: > :repeat_second: thirty > > > In the log, I only see "Experiment fired at thirty second mark." Why isn''t > the first entry for experiment worker firing? Perhaps, I have this set up > wrong?Because it needs different method names for such a firing. As you might have noticed, currently you have two values with same key in configuration file. -- Let them talk of their oriental summer climes of everlasting conservatories; give me the privilege of making my own summer with my own coals. http://gnufied.org
Meng Kuan
2008-Jan-29 02:34 UTC
[Backgroundrb-devel] Scheduling same worker/method at different times with different args
On 29 Jan 2008, at 4:15 AM, hemant wrote:> On Tue, Jan 29, 2008 at 1:02 AM, Scott Ward <scott at shefield.com> > wrote: >> I need to run the same worker''s method twice per day with different >> arguments. Unfortunately, only the second entry in the schedule >> is firing. >> >> I created an experimental worker to verify this: >> >> Worker: >> class ExperimentWorker < BackgrounDRb::MetaWorker >> set_worker_name :experiment_worker >> def create(args = nil) >> # this method is called, when worker is loaded for the first time >> end >> >> def experiment(args = {}) >> logger.info "#{Time.now} - Experiment fired at #{args >> [:repeat_second]} >> second mark." >> end >> end >> >> >> In backgroundrb.yml: >> :schedules: >> :experiment_worker: >> :experiment: >> :trigger_args: "0 * * * * * *" >> :data: >> :repeat_second: zero >> :experiment: >> :trigger_args: "30 * * * * * *" >> :data: >> :repeat_second: thirty >> >> >> In the log, I only see "Experiment fired at thirty second mark." >> Why isn''t >> the first entry for experiment worker firing? Perhaps, I have >> this set up >> wrong? > > > Because it needs different method names for such a firing. As you > might have noticed, currently you have two values with same key in > configuration file. >You can try using alias_method to get a different method name: alias_method :experiment2, :experiment Note: the alias_method call should come _after_ the actual "experiment" method definition. Then your backgroundrb.yml becomes: :schedules: :experiment_worker: :experiment: :trigger_args: "0 * * * * * *" :data: :repeat_second: zero :experiment2: :trigger_args: "30 * * * * * *" :data: :repeat_second: thirty
hemant
2008-Jan-29 03:50 UTC
[Backgroundrb-devel] Scheduling same worker/method at different times with different args
On Tue, Jan 29, 2008 at 8:04 AM, Meng Kuan <mengkuan at gmail.com> wrote:> > > On 29 Jan 2008, at 4:15 AM, hemant wrote: > > > On Tue, Jan 29, 2008 at 1:02 AM, Scott Ward <scott at shefield.com> > > wrote: > >> I need to run the same worker''s method twice per day with different > >> arguments. Unfortunately, only the second entry in the schedule > >> is firing. > >> > >> I created an experimental worker to verify this: > >> > >> Worker: > >> class ExperimentWorker < BackgrounDRb::MetaWorker > >> set_worker_name :experiment_worker > >> def create(args = nil) > >> # this method is called, when worker is loaded for the first time > >> end > >> > >> def experiment(args = {}) > >> logger.info "#{Time.now} - Experiment fired at #{args > >> [:repeat_second]} > >> second mark." > >> end > >> end > >> > >> > >> In backgroundrb.yml: > >> :schedules: > >> :experiment_worker: > >> :experiment: > >> :trigger_args: "0 * * * * * *" > >> :data: > >> :repeat_second: zero > >> :experiment: > >> :trigger_args: "30 * * * * * *" > >> :data: > >> :repeat_second: thirty > >> > >> > >> In the log, I only see "Experiment fired at thirty second mark." > >> Why isn''t > >> the first entry for experiment worker firing? Perhaps, I have > >> this set up > >> wrong? > > > > > > Because it needs different method names for such a firing. As you > > might have noticed, currently you have two values with same key in > > configuration file. > > > > You can try using alias_method to get a different method name: > > alias_method :experiment2, :experiment > > Note: the alias_method call should come _after_ the actual > "experiment" method definition. > > > Then your backgroundrb.yml becomes: > > > :schedules: > :experiment_worker: > :experiment: > :trigger_args: "0 * * * * * *" > :data: > :repeat_second: zero > :experiment2: > > :trigger_args: "30 * * * * * *" > :data: > :repeat_second: thirty >There is a patch by Andy, in trac for enabling this kind of behaviour, we can think of applying that.
Scott Ward
2008-Jan-29 16:52 UTC
[Backgroundrb-devel] Scheduling same worker/method at differenttimes with different args
Cool. That worked like a charm. -----Original Message----- From: backgroundrb-devel-bounces at rubyforge.org [mailto:backgroundrb-devel-bounces at rubyforge.org] On Behalf Of Meng Kuan Sent: Monday, January 28, 2008 6:34 PM To: backgroundrb-devel at rubyforge.org Subject: Re: [Backgroundrb-devel] Scheduling same worker/method at differenttimes with different args On 29 Jan 2008, at 4:15 AM, hemant wrote:> On Tue, Jan 29, 2008 at 1:02 AM, Scott Ward <scott at shefield.com> > wrote: >> I need to run the same worker''s method twice per day with different >> arguments. Unfortunately, only the second entry in the schedule is >> firing. >> >> I created an experimental worker to verify this: >> >> Worker: >> class ExperimentWorker < BackgrounDRb::MetaWorker >> set_worker_name :experiment_worker >> def create(args = nil) >> # this method is called, when worker is loaded for the first time >> end >> >> def experiment(args = {}) >> logger.info "#{Time.now} - Experiment fired at #{args >> [:repeat_second]} second mark." >> end >> end >> >> >> In backgroundrb.yml: >> :schedules: >> :experiment_worker: >> :experiment: >> :trigger_args: "0 * * * * * *" >> :data: >> :repeat_second: zero >> :experiment: >> :trigger_args: "30 * * * * * *" >> :data: >> :repeat_second: thirty >> >> >> In the log, I only see "Experiment fired at thirty second mark." >> Why isn''t >> the first entry for experiment worker firing? Perhaps, I have >> this set up >> wrong? > > > Because it needs different method names for such a firing. As you > might have noticed, currently you have two values with same key in > configuration file. >You can try using alias_method to get a different method name: alias_method :experiment2, :experiment Note: the alias_method call should come _after_ the actual "experiment" method definition. Then your backgroundrb.yml becomes: :schedules: :experiment_worker: :experiment: :trigger_args: "0 * * * * * *" :data: :repeat_second: zero :experiment2: :trigger_args: "30 * * * * * *" :data: :repeat_second: thirty _______________________________________________ Backgroundrb-devel mailing list Backgroundrb-devel at rubyforge.org http://rubyforge.org/mailman/listinfo/backgroundrb-devel