我试图用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
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
℃。监听器:
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。尝试捆绑exec sidekiq -d -e production sidekiq -q default -C config / sidekiq.yml ,但不是结果。 sidekiq.rb 为空。
答案 0 :(得分:1)
我认为您可以通过以下步骤解决此问题:
require 'sidekiq/web'
然后,mount Sidekiq::Web => '/sidekiq'
/sidekiq
查看是否有工人/任务/队列binding.pry
放在那里binding.pry
放在那里希望有所帮助: - )
答案 1 :(得分:1)
问题解决了。我不得不运行sidekiq:
捆绑exec sidekiq-r ./server.rb-L log / sidekiq.log 也在server.rb
要求&#39; sidekiq&#39;
Sidekiq.configure_server do | config | config.redis = {url:&#39; redis:// localhost:6379/0&#39; } 端
Sidekiq.configure_client do | config | config.redis = {url:&#39; redis:// localhost:6379/0&#39; } 端