Cant start resque worker - ruby-on-rails

I've installed resque gem, gem install resque.
And I tried to start the workers :
bundle exec rake environment resque:work
Resulting in :
rake aborted!
Don't know how to build task 'resque:work' (see --tasks)
(See full trace by running task with --trace)
When I do rake -T no resque tasks appear, what am I going wrong here?

You should put the resque gem into the Gemfile instead of installing it directly.
Installation documentation (as of the time of writing) says that...
To start a worker, add this to a file in lib/tasks (ex: lib/tasks/resque.rake):
require 'resque/tasks'

Related

Jobs with Resque gives "Don't know how to build task 'jobs:work'" on Heroku

I followed the tutorial at https://devcenter.heroku.com/articles/queuing-ruby-resque to queue and run background jobs in a Rails app. After queueing the jobs, it doesn't seem to run any of the jobs since in the console I can see the job has not been processed
>Resque.info
=> {:pending=>1, :processed=>0, :queues=>1, :workers=>0, :working=>0, :failed=>0, :servers=>["redis://dory.redistogo.com:9826/0"], :environment=>"production"}
If I try to do (locally)
bundle exec rake jobs:work
I get
rake aborted!
Don't know how to build task 'jobs:work'
On heroku, if I try
heroku run rake jobs:work
I again get `Don't know how to build task'
In my Rakefile, I have require 'resque/tasks' and in my Procfile I have
resque: env TERM_CHILD=1 bundle exec rake jobs:work
resque: env TERM_CHILD=1 bundle exec rake jobs:work
I have the Resque and redis gems in my Gemfile, but not delayed_job.
Update:
Here is my Rakefile:
#!/usr/bin/env rake
require File.expand_path('../config/application', __FILE__)
Guard::Application.load_tasks
/lib/tasks is empty. I have a worker in app/workers that I am enqueueing in a controller.
This doesn't appear to have anything to do with Heroku, if it doesn't work locally. You'll have to reveal some of your source to help people help you. For example, what's your Rakefile look like? The demo app in that article defines one with a Rake task with the task. Have you defined your rake task and added the appropriate gem references?
Try resque:work instead of jobs:work and see if that beings the desired results.
You just need to add require 'resque/tasks' in your Rakefile, then on the command line:
QUEUE=file_serve rake environment resque:work
Where file_serve is the name of your job (the class would be FileServeJob).
See the docs here - I found them slightly confusing since the setup and run info comes after the job class creation.

What does 'bundle exec rake' versus rake do?

What is the difference between doing:
bundle exec rake
and
rake
I see people doing both, I never do bundle before my commands, curious what the reason for it is?
bundle exec executes a command in the context of the bundle.
This command executes the command, making all gems specified in the Gemfile available to require in Ruby programs.
Very useful when you have many applications with different versions of gems used
in them.
Please see docs for more information: http://gembundler.com/man/bundle-exec.1.html
bundle exec runs the command after it in the environment of Bundler. So say you had rake 0.9 in you Gemfile, but rake 10 installed in RubyGems.bundle exec rake will run rake 0.9 instead of rake 10.

Running rake task from a daemon

I have a daemon that i made using the daemons gem
I run it and it just closes without error, but the script doesn't seem to be actually running.
I'm running a rake task from it, will daemons run the commands inside from the directory it was called from?
This is the script
require 'rubygems'
require 'daemons'
Daemons.run('rake mytask')
the rake task has a loop which should stop it from exiting.
I'm not sure the way you're doing this will work with daemons. Can you move the rake task into an .rb file? Daemons is going to pass what ever you have in the run command to ruby, so in essence it is trying to run "ruby rake mytask"

Ruby on Rails 3.0 Delayed Job

I've added gem 'delayed_job' to my gem file and ran a bundle install.
After that I ran rails generate delayed_job
I've created a controller named Online with a method online.
In turn after the method declaration I added the following line:
handle_asynchronously :online
I start up my app, but the code in that method does not run.
What am I doing wrong?
I'd guess that you haven't done rake jobs:work anywhere. From the fine manual:
Running the jobs
You can invoke rake jobs:work which will start working off jobs. You can cancel the rake task with CTRL-C.
You might want to set up Foreman to start the Rails server and the Rake task at the same time in your development environment; there's even a Railscast about it:
http://railscasts.com/episodes/281-foreman

Asset rake tasks not available on Rails 3.1 app in production

When I run "bundle exec rake -T" in development, the assets:clear and assets:precompile tasks show up, but if I prefix that command with RAILS_ENV=production, or run it on a server where that variable is set, they don't. Has anyone run into this?
I'd removed rails/all from the application.rb and replaced it with the individual railties, excluding activerecord. Turns out you also need to require the sprockets railtie.

Resources