Rails开发环境Resque.enqueue不会创建作业

时间:2013-06-25 14:15:20

标签: ruby-on-rails redis resque

我遇到了像Rails custom environment Resque.enqueue does not create jobs这样的问题,但那里的解决方案对我不起作用。

我正在使用Resque进行几个异步作业。它适用于staging环境,但出于某种原因,它已停止在development环境中工作。

例如,如果我运行以下内容:

$ rails c development

> Resque.enqueue(MyLovelyJob, 1)

什么都没有排队。我使用resque-web

检查Resque

如果我在分段上运行它 - 它可以正常工作。

$ rails c staging

> Resque.enqueue(MyLovelyJob, 1)

我试图复制2环境,它们似乎使用完全相同的配置(database.yml,config / environment等),但development仍无效。

如果我这样做

 > Resque.enqueue(UpdateInstancesData, 2)
 > => true

 > Resque.info
 > => {
 >       :pending => 0,
 >     :processed => 0,
 >        :queues => 0,
 >       :workers => 1,
 >       :working => 0,
 >        :failed => 0,
 >       :servers => [
 >       [0] "redis://127.0.0.1:6379/0"
 >   ],
 >   :environment => "development"
 > }

建议在哪里查看以进行调试?

我正在通过领班运行该应用程序。我的Procfile看起来像:

  

faye:rackup faye.ru -s thin -E production

     

worker1:bundle exec rake resque:work QUEUE = * VERBOSE = 1

     

worker2:bundle exec rake resque:work QUEUE = * VERBOSE = 1

     

clock:bundle exec rake resque:scheduler VERBOSE = 1

     

web:bundle exec rails s


对于staging,如上所述,一切正常,而工头的日志是:

17:03:42 clock.1       | 2013-06-26 17:03:42 Reloading Schedule
17:03:42 clock.1       | 2013-06-26 17:03:42 Loading Schedule
17:03:42 clock.1       | 2013-06-26 17:03:42 Scheduling logging_test
17:03:42 clock.1       | 2013-06-26 17:03:42 Schedules Loaded
17:03:43 worker2.1     | *** Starting worker ttttt-mbp.local:69573:*
17:03:43 worker2.1     | *** Registered signals
17:03:43 worker2.1     | *** Running before_first_fork hooks
17:03:43 worker1.1     | *** Starting worker ttttt-mbp.local:69572:*
17:03:43 worker1.1     | *** Registered signals
17:03:43 worker2.1     | *** Checking another_queue
17:03:43 worker2.1     | *** Checking anotherqueue
17:03:43 worker2.1     | *** Checking statused
17:03:43 worker2.1     | *** Found job on statused
17:03:43 worker2.1     | *** got: (Job{statused} | LoggingTest | ["57e89a1c1b24ce6866bcf5d0e1c07f01", {}])

17:06:30 clock.1       | 2013-06-26 17:06:30 queueing LoggingTest (logging_test)
17:06:33 worker1.1     | *** Checking another_queue
17:06:33 worker2.1     | *** Checking another_queue
17:06:33 worker1.1     | *** Checking anotherqueue
17:06:33 worker2.1     | *** Checking anotherqueue
17:06:33 worker1.1     | *** Found job on anotherqueue
17:06:33 worker1.1     | *** got: (Job{anotherqueue} | LoggingTest | ["0d976869a945766e0cfeca83e7349305", {}])
17:06:33 worker1.1     | *** resque-1.24.1: Processing anotherqueue since 1372259193 [LoggingTest]
17:06:33 worker1.1     | *** Running before_fork hooks with [(Job{anotherqueue} | LoggingTest | ["0d976869a945766e0cfeca83e7349305", {}])]
17:06:33 worker1.1     | *** resque-1.24.1: Forked 69955 at 1372259193
17:06:33 worker2.1     | *** resque-1.24.1: Forked 69956 at 1372259193
17:06:33 worker1.1     | *** Running after_fork hooks with [(Job{anotherqueue} | LoggingTest | ["0d976869a945766e0cfeca83e7349305", {}])]
17:06:33 worker1.1     | JOB :: LoggingTest
17:06:33 worker1.1     | 55555
17:06:33 worker1.1     | *** done: (Job{anotherqueue} | LoggingTest | ["0d976869a945766e0cfeca83e7349305", {}])

而对于development,它似乎没有排队然后找到工作。如果队列中已有作业(待处理,暂存环境中遗留),则开发人员不会处理该作业。

17:01:23 clock.1       | 2013-06-26 17:01:23 Reloading Schedule
17:01:23 clock.1       | 2013-06-26 17:01:23 Loading Schedule
17:01:23 clock.1       | 2013-06-26 17:01:23 Scheduling logging_test
17:01:23 clock.1       | 2013-06-26 17:01:23 Scheduling update_instances_data
17:01:23 clock.1       | 2013-06-26 17:01:23 Schedules Loaded

17:03:10 clock.1       | 2013-06-26 17:03:10 queueing LoggingTest (logging_test)
17:03:14 worker1.1     | *** Checking another_queue
17:03:14 worker2.1     | *** Checking another_queue
17:03:14 worker1.1     | *** Checking anotherqueue
17:03:14 worker2.1     | *** Checking anotherqueue
17:03:14 worker1.1     | *** Checking statused
17:03:14 worker2.1     | *** Checking statused

2 个答案:

答案 0 :(得分:24)

问题原因是我的Gemfile中的gem 'resque_spec'组也有:development。显然这是一件非常错误的事情...

答案 1 :(得分:0)

我的问题是有孤儿工人在后台运行。他们正在找工作。

通过重新启动redis,所有工作人员都死了。