1

我正在尝试用wisper-sidekiq gem 做一个小例子。队列已创建,但未启动。为什么?我将描述您正在执行的步骤,我认为这会更容易。我希望能得到你的帮助。

A.控制器:

class BooksController < ApplicationController
def create
    service = CreateBook.new
    service.subscribe(ActivityListener, async: true)
    service.on(:reserver_item_successfull) { |book| redirect_to book_path(book.id) }
    service.on(:reserver_item_failed)      { |book| @book = Book.new(book_params); respond_with(@book) }
    service.execute(current_user, book_params)
end

B、服务:

require 'wisper/sidekiq'
require 'sidekiq/api'

class CreateBook
  include Wisper::Publisher

  def execute(performer, attributes)
    book = Book.new(attributes)
    if book.valid?
      book.save
      broadcast(:reserver_item_successfull, performer, book)
    else
      broadcast(:book_failed, performer, book)
    end
  end
end

C. 听众:

class ActivityListener
  def self.reserver_item_successfull(performer, book)
    puts performer.name.to_s + ", book: " + book.title.to_s
  end
end

当我保存这本书时,当然会创建一个队列。但:

  • sidekiq 静默(日志为空,但已创建队列)
  • redis 也沉默

也许我错了启动redis(redis-server)或sidekiq(bundle exec sidekiq)?请帮我。

PS尝试bundle exec sidekiq -d -e production sidekiq -q default -C config/sidekiq.yml,但没有结果。sidekiq.rb空。

4

2 回答 2

1

我认为您可以通过以下步骤解决此问题:

  • require 'sidekiq/web'接着,mount Sidekiq::Web => '/sidekiq'
  • /sidekiq看看是否有工人/任务/队列
  • 如果没有
    • 你的redis可能有问题
    • 或你的代码,放在binding.pry那里
  • 如果有,一定是你的代码有问题,放在binding.pry那里

希望有帮助:-)

于 2015-02-25T09:05:37.780 回答
1

问题已经解决了。我不得不运行sidekiq:

bundle exec sidekiq-r ./server.rb-L log/sidekiq.log 也在 server.rb

需要'sidekiq'

Sidekiq.configure_server 做 |config| config.redis = { url: 'redis://localhost:6379/0' } 结束

Sidekiq.configure_client 做 |config| config.redis = { url: 'redis://localhost:6379/0' } 结束

于 2015-02-25T17:11:12.627 回答