Module: SuckerPunch

Defined in:
lib/sucker_punch/testing.rb,
lib/sucker_punch.rb,
lib/sucker_punch/job.rb,
lib/sucker_punch/queue.rb,
lib/sucker_punch/counter.rb,
lib/sucker_punch/railtie.rb,
lib/sucker_punch/version.rb,
lib/sucker_punch/async_syntax.rb,
lib/sucker_punch/testing/inline.rb,
lib/generators/sucker_punch/job_generator.rb

Overview

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

Defined Under Namespace

Modules: Counter, Generators, Job Classes: AsyncProxy, Queue, Railtie

Constant Summary collapse

RUNNING =
Concurrent::AtomicBoolean.new(true)
VERSION =
"3.2.0"

Class Method Summary collapse

Class Method Details

.default_exception_handler(ex, klass, args) ⇒ Object



21
22
23
24
25
26
# 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_loggerObject



32
33
34
35
36
# File 'lib/sucker_punch.rb', line 32

def default_logger
  l = Logger.new(STDOUT)
  l.level = Logger::INFO
  l
end

.exception_handlerObject



13
14
15
# File 'lib/sucker_punch.rb', line 13

def exception_handler
  @exception_handler ||= method(:default_exception_handler)
end

.exception_handler=(handler) ⇒ Object



17
18
19
# File 'lib/sucker_punch.rb', line 17

def exception_handler=(handler)
  @exception_handler = handler
end

.loggerObject



28
29
30
# File 'lib/sucker_punch.rb', line 28

def logger
  @logger ||= default_logger
end

.logger=(log) ⇒ Object



38
39
40
# File 'lib/sucker_punch.rb', line 38

def logger=(log)
  @logger = (log ? log : Logger.new('/dev/null'))
end

.shutdown_timeoutObject



42
43
44
45
# 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) ⇒ Object



47
48
49
# File 'lib/sucker_punch.rb', line 47

def shutdown_timeout=(timeout)
  @shutdown_timeout = timeout
end