Why not exec queue?
chip-and-dail opened this issue · 5 comments
I'm trying to make a small example. The queue is created, but it does not start. Why? I will describe the steps that you are doing, I think it will be easier. I hope for your help.
A. controller:
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. service:
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. listener:
class ActivityListener
def self.reserver_item_successfull(performer, book)
puts performer.name.to_s + ", book: " + book.title.to_s
end
end
When I save the book, then of course creates a queue. But:
Maybe I'm wrong start redis (redis-server) or sidekiq (bundle exec sidekiq)? Please help me.
Does Sidekiq work without Wisper, i.e. can you get a job to run on Sidekiq at all?
Are you sure that the event is being broadcast (i.e. the model is valid)?
By the way doesn't the 3 enqueued jobs indicate it is working?
Sorry, misunderstood your question.
- Model is valid. Because we see that in Sidekiq is added to the task.
- If you turn off Sidekiq, the task is still queued.
- The jobs are very simple. Inside only puts.
If I change from this:
service.subscribe(ActivityListener, async: true)
to this:
service.subscribe(ActivityListener.new)
and from this:
def selft.reserver_item_successfull(performer, book)
to this:
def reserver_item_successfull(performer, book)
Then the method reserver_item_successfull works. But without sidekiq.
I think I got confused.
The problem is solved. I had to run sidekiq:
bundle exec sidekiq-r ./server.rb-L log/sidekiq.log
also in server.rb
require 'sidekiq'
Sidekiq.configure_server do |config|
config.redis = { url: 'redis://localhost:6379/0' }
end
Sidekiq.configure_client do |config|
config.redis = { url: 'redis://localhost:6379/0' }
end
Sorry.
Glad you got it sorted 😄