Ruby and Resque app: can't start

I have this little ruby ​​app, not Ruby on Rails - pure Ruby.

I followed the instructions and I can enqueue things and see that everything is correctly enqueued with resque-web

.

However, I have a problem to get started. The documentation states the launch bin/resque work

to start the worker.

So the message starts -bash: bin/resque: No such file or directory

All over the internet, people have the same problem, but for a Rails application, not pure Ruby. The solution seems to contain something in the rakefile that I don't have.

How can I start my worker? Many thanks!

+3


source to share


1 answer


The key to solving your problem is the rake.

Resque includes three rake problems. All you need is a rakefile that requires 'resque/tasks'

you to use them. When you ask Reik about his command list, you will see three tasks that are included in Resque:

rake resque:failures:sort  # Sort the 'failed' queue for the redis_multi_queue failure backend
rake resque:work           # Start a Resque worker
rake resque:workers        # Start multiple Resque workers

      

The one you are looking for (to start one working) is resque:work

. You will tell which queue to listen to the environment variable QUEUE

. So your worker's start will be something like this:

QUEUE=your_queue_name rake resque:work

...

Alternatively, you can listen to all queues with QUEUES=*

.

EDIT:



Here's a more complete example. Create a file named rakefile

:

require 'resque/tasks'
require 'resque'

class Worker
  @queue = :default

  def self.perform(my_arg)
    puts my_arg
  end
end

task :hello do
    Resque.enqueue(Worker, 'hello')
end

      

Then in one terminal type TERM_CHILD=1 QUEUE=default rake resque:work

. This will start a worker watching the default queue . It will print out any argument, the job goes to its class method perform

.

In the second terminal type rake hello

. This will trigger an assignment for the class Worker

, passing a string hello

as an argument (which will be passed to the method perform

in the class Worker

). He knows to push into the queue default

by looking at the property @queue

on Worker

.

You will see hello printed in the terminal where you started the worker.

This example doesn't do anything useful, and you don't put the whole thing in your rakefile, but I think it's a good starting point to start modifying it and creating your own.

+6


source







All Articles