Created
September 29, 2015 14:02
-
-
Save novohispano/eaa73a6c940c0544c15b to your computer and use it in GitHub Desktop.
ActiveJob Example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class GenerateQuotesJob < ActiveJob::Base | |
queue_as :default | |
def perform | |
Quote.generate | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
web: bundle exec rails s | |
workers: bundle exec sidekiq |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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