You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on May 26, 2021. It is now read-only.
Mikhail Chuprysnki edited this page Jun 8, 2016
·
6 revisions
Rails 4.2 introduced ActiveJob, a standard interface for job runners. Here is how to use Resque with ActiveJob.
Make sure you have Redis installed and gem 'resque' is in your Gemfile
Set Resque as queue adapter in config/application.rb.
config.active_job.queue_adapter = :resque
In your Rakefile add the following to access resque rake tasks
require 'resque/tasks'
Generate your job
rails g job Cleanup
This will generate new job at app/jobs folder:
classCleanupJob < ActiveJob::Basequeue_as:defaultdefperform(arg1,arg2)#your long running code hereendend
Run this job anywhere at your code like this:
#just runCleanupJob.perform_later(arg1,arg2)#or set the queue nameCleanupJob.set(queue: user.name).perform_later(arg1,arg2)#or set the delayCleanupJob.set(wait: 1.week).perform_later(arg1,arg2)#or run immediatelyCleanupJob.perform_now(arg1,arg2)
Run Redis server
redis-server /usr/local/etc/redis.conf
Run the following in console (otherwise your workers will not start (just pending))
QUEUE=* rake resque:work
Additionally, you can mount web-version of Resque to your project, add this to your routes.rb
require'resque/server'mountResque::Server,at: '/jobs'#or if you would like to protect this with Devisedevise_for:usersauthenticate:userdomountResque::Server,at: '/jobs'end