我正在尝试用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为空。