有没有办法确定Resque工作者或应用程序中是否正在执行ActiveJob?

时间:2016-04-30 00:56:50

标签: ruby-on-rails resque rails-activejob resque-scheduler

我的rails应用程序中有一个Job,它来自ActiveJob :: Base,有两种方式可以调用:

  1. 每天使用ResqueScheduler,由Resque工作人员接收并处理
  2. 通过#perform_now调用在应用内,因此应用程序处理它。
  3. 我是否有办法在工作中确定Resque工作人员是否正在处理它?<​​/ p>

2 个答案:

答案 0 :(得分:0)

您应该在服务器日志中看到对ActiveJob的引用。

[ActiveJob] [<YOUR-JOB-CLASS>] [b8ed2ecb-10ce-433d-8ddb-33a04c8021cd]    Performing <YOUR-JOB-CLASS> from Resque(default)...

这不是决定性的,但它是执行代码的上下文中的一个强有力的指标。

答案 1 :(得分:0)

您可以使用 NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerWillAppear:", name: "PlayerWillAppear", object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerWillDisappear:", name: "PlayerWillDisappear", object: nil) func playerWillAppear(notification: NSNotification) { print("A Player will be opened now") } func playerWillDisappear(notification: NSNotification) { print("A Player will be closed now") } 来确定您是否在Rails应用程序内,或者您是否处于Resque环境中。