Resources

Download Source Code

Summary

# Terminal
bundle add resque
bin/rails g job slow_task
bin/rails resque:work
QUEUE=critical,default,* bin/rails resque:work
INTERVAL=0.1 COUNT=2 QUEUE=* bin/rails resque:workers

# lib/tasks/resque.rake
require 'resque/tasks'
task 'resque:setup' => :environment

# config/application.rb
config.active_job.queue_adapter = :resque

# app/jobs/slow_task_job.rb
class SlowTaskJob < ApplicationJob
  queue_as :default

  def perform(timestamp)
    puts timestamp
    sleep(2)
  end
end

# welcome_controller.rb
def index
  SlowTaskJob.perform_later(Time.current)
end

# config/routes.rb
Rails.application.routes.draw do
  require 'resque/server'
  mount Resque::Server, at: '/jobs', as: :jobs

  # authenticate :user, lambda { |u| u.admin? } do
  #   mount Resque::Server, at: '/jobs', as: :jobs
  # end

  root to: 'welcome#index'
end

# views/layouts/application.html.erb
<%= link_to "Jobs", jobs_path %>