2009-10-30 57 views
0

我试图做到以下几点:的Rails插件backgroundRB需要安排它和队列数据库persistancy

  1. 运行工人,并在其中一个方法,每15分钟
  2. 有一个日志上次运行时的作业,在数据库表 bdrd_job_queue中。

我所做的:

我有一个时间表,我backgroundRB.yml文件每15分钟

方法调用有persistent_job.finish!电话,但它不工作,因为 persistent_job对象为零。

我怎样才能确保它已经登录到数据库中,但是仍然自动从backgroundRB.yml中计划 ?

+0

据我了解,我需要排队它,而不是通过我的backgroundRB.yml文件调度它的。但是,这并不能满足我所有的需求......还有其他建议吗? – user62605 2009-11-03 17:15:32

回答

0

我终于能够做到了。

解决方法是安排将它排入数据库的任务,计划立即运行。

在你的工人...

class NotificationWorker < BackgrounDRb::MetaWorker 
    set_worker_name :notification_worker 

    def create(args = nil) 
    end 

    def queue_notify_changes(args = nil) 
    BdrbJobQueue.insert_job(:worker_name => 'notification_worker', 
          :worker_method => 'notify_new_changes_DAEMON', 
          :args => 'hello_world', 
          :scheduled_at => Time.now.utc, 
          :job_key => 'email_changes_notification_task') 
    end 
    def notify_new_changes_DAEMON 
    #Do Incredibly cool stuff here 
    end 

在config文件中backgroundrb.yml

--- 
:backgroundrb: 
    :ip: 0.0.0.0 
    :port: 11006 
    :environment: production 
    :log: foreground 
    :debug_log: true 
    :persistent_disabled: false 
    :persistent_delay: 10 

:schedules: 
    :notification_worker: 
    :queue_notify_changes: 
     :trigger_args: 0 0 0 * * *