不通过 wisper-sidekiq 启动队列

Not start the queue by wisper-sidekiq

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

一个。控制器:

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

乙。服务:

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

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

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

P.S。尝试 bundle exec sidekiq -d -e production sidekiq -q default -C config/sidekiq.yml,但不是结果。 sidekiq.rb空.

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

  • require 'sidekiq/web' 然后 mount Sidekiq::Web => '/sidekiq'
  • /sidekiq看看有没有workers/tasks/queues
  • 如果没有
    • 你的redis可能有问题
    • 或您的代码,将 binding.pry 放在那里
  • 如果有,一定是你的代码有问题,把 binding.pry 放在那里

希望对您有所帮助:-)

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

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

需要'sidekiq'

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

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