module SuckerPunch

Include this in your tests to simulate a fake job queue. Jobs won't be executed as they normal would be the thread pool. They'll instead be pushed to a fake queue to be checked in a test environment.

Include in your test_helper.rb:

require 'sucker_punch/testing'

In your application code:

LogJob.perform_async(1, 2, 3)

In your tests:

LogJob.jobs => [{ "args" => [1, 2, 3]]

Include this in your tests to simulate immediate execution of your asynchronous jobs

class LogJob

include SuckerPunch::Job

def perform(*args)
  # log the things
end

end

To trigger asynchronous job:

LogJob.perform_async(1, 2, 3)

Include inline testing lib:

require 'sucker_punch/testing/inline'

LogJob.perform_async(1, 2, 3) is now synchronous LogJob.perform_in(1, 2, 3) is now synchronous

Constants

RUNNING
VERSION

Public Class Methods

default_exception_handler(ex, klass, args) click to toggle source
# File lib/sucker_punch.rb, line 21
def default_exception_handler(ex, klass, args)
  msg = "Sucker Punch job error for class: '#{klass}' args: #{args}\n"
  msg += "#{ex.class} #{ex}\n"
  msg += "#{ex.backtrace.nil? ? '' : ex.backtrace.join("\n")}"
  logger.error msg
end
default_logger() click to toggle source
# File lib/sucker_punch.rb, line 32
def default_logger
  l = Logger.new(STDOUT)
  l.level = Logger::INFO
  l
end
exception_handler() click to toggle source
# File lib/sucker_punch.rb, line 13
def exception_handler
  @exception_handler ||= method(:default_exception_handler)
end
exception_handler=(handler) click to toggle source
# File lib/sucker_punch.rb, line 17
def exception_handler=(handler)
  @exception_handler = handler
end
logger() click to toggle source
# File lib/sucker_punch.rb, line 28
def logger
  @logger ||= default_logger
end
logger=(log) click to toggle source
# File lib/sucker_punch.rb, line 38
def logger=(log)
  @logger = (log ? log : Logger.new('/dev/null'))
end
shutdown_timeout() click to toggle source
# File lib/sucker_punch.rb, line 42
def shutdown_timeout
  # 10 seconds on heroku, minus a grace period
  @shutdown_timeout ||= 8
end
shutdown_timeout=(timeout) click to toggle source
# File lib/sucker_punch.rb, line 47
def shutdown_timeout=(timeout)
  @shutdown_timeout = timeout
end