Skip to content

Instantly share code, notes, and snippets.

@novohispano
Created September 29, 2015 14:02
Show Gist options
  • Save novohispano/eaa73a6c940c0544c15b to your computer and use it in GitHub Desktop.
Save novohispano/eaa73a6c940c0544c15b to your computer and use it in GitHub Desktop.
ActiveJob Example
source 'https://rubygems.org'
gem 'rails', '4.2.4'
gem 'sqlite3'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'bootstrap-sass', '~> 3.3.5'
gem 'faker', '~> 1.5.0'
gem 'sidekiq', '~> 3.5.0'
gem 'sinatra'
gem 'foreman'
group :development, :test do
gem 'pry'
gem 'better_errors'
gem 'binding_of_caller'
end
class GenerateQuotesJob < ActiveJob::Base
queue_as :default
def perform
Quote.generate
end
end
web: bundle exec rails s
workers: bundle exec sidekiq
class QuotesController < ApplicationController
def index
@quotes = Quote.all
end
def create
GenerateQuotesJob.set(wait_until: Time.current.next_week).perform_later
redirect_to :back, success: 'The quotes were generated successfully.'
end
end
require 'sidekiq/web'
Rails.application.routes.draw do
mount Sidekiq::Web, at: '/sidekiq'
root 'site#show'
resources :books, only: [:index, :create]
resources :quotes, only: [:index, :create]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment