Skip to content

Instantly share code, notes, and snippets.

Redis and Resque

What this guide will cover: the code you will need in order to include Redis and Resque in your Rails app, and the process of creating a background job with Resque.

What this guide will not cover: installing Ruby, Rails, or Redis.

Note: As of this writing I am still using Ruby 1.9.3p374, Rails 3.2.13, Redis 2.6.11, and Resque 1.24.1. I use SQLite in development and Postgres in production.

Background jobs are frustrating if you've never dealt with them before. Over the past few weeks I've had to incorporate Redis and Resque into my projects in various ways and every bit of progress I made was very painful. There are many 'gotchas' when it comes to background workers, and documentation tends to be outdated or scattered at best.

# in spec/support/omniauth_macros.rb
module OmniauthMacros
def mock_auth_hash
# The mock_auth configuration allows you to set per-provider (or default)
# authentication hashes to return during integration testing.
OmniAuth.config.mock_auth[:twitter] = {
'provider' => 'twitter',
'uid' => '123545',
'user_info' => {
'name' => 'mockuser',

#Lew's Opinionated Guide to Delivering Features#


  1. First, understand the story.

Do you understand the story completely? If not, talk to the product owner to clarify your understanding.

Is the story a logically cohesive grouping of functionality? If not, can it be broken into multiple stories?

Do the points assigned make sense given your current level of understanding of the story? If not, can it be broken into multiple stories?

=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
class Sieve
attr_reader :values
def initialize(max)
@values = (2..max).to_a
end
def primes
values.each do |value|
class NilClass
def join
""
end
end
class Chunks
attr_reader :value
def initialize(value)
@garciadanny
garciadanny / word_problem.rb
Created March 6, 2013 16:41 — forked from jcasimir/word_problem.rb
REGULAR EXPRESSIONS
class WordProblem
attr_reader :equation
def initialize(equation)
@equation = equation
end
def answer
calculate
end
require 'time'
class Gigasecond
attr_reader :quantity
IN_SECONDS = 1_000_000_000
def initialize(quantity)
@quantity = quantity
end
@garciadanny
garciadanny / seconds_old.rb
Last active December 14, 2015 06:08 — forked from burtlo/example2.rb
require 'date'
# puts "What are you? #{ARGV} #{ARGV.class}"
# Called as in `ruby example2.rb 1977 10 30`
# birthdate = ARGV.map {|arg| arg.to_i }
birthdate = [ 1977, 10, 30 ]
# year, month, day = [ 1977, 10, 30 ]
# birth_in_seconds = Date.new(year,month,day).to_time.to_i
@garciadanny
garciadanny / Rakefile
Last active December 14, 2015 01:39 — forked from burtlo/Rakefile
# http://rake.rubyforge.org/
$:.push('lib')
require 'sales_engine'
def cleanup
puts "Cleaning Up My Mess"
end
task :environment do
puts "Loading Environment"