Module: Pace

Defined in:
lib/pace/mock.rb,
lib/pace.rb,
lib/pace/worker.rb,
lib/pace/version.rb,
lib/pace/load_average.rb

Overview

Ease testing by mocking the event loop

Instead of having to detect and stop the event loop yourself, this helper simply returns all jobs in the queue and shuts down the loop.

require "pace/mock"

# Fire it up
Pace::Mock.enable

# Add some jobs
Resque.enqueue(Work, ...)
Resque.enqueue(Work, ...)

# Create a worker with a block that doesn't need to stop the loop
worker = Pace::Worker.new(:queue => "queue")
worker.start do |job|
  puts job.inspect
end

# Turn it off when you're done
Pace::Mock.disable

Defined Under Namespace

Modules: LoadAverage, Mock Classes: Worker

Constant Summary collapse

VERSION =
"0.0.6"

Class Method Summary collapse

Class Method Details

.log(message, start_time = nil) ⇒ Object



15
16
17
18
19
20
21
# File 'lib/pace.rb', line 15

def self.log(message, start_time = nil)
  if start_time
    logger.info("%s (%0.6fs)" % [message, Time.now - start_time])
  else
    logger.info("%s" % message)
  end
end

.start(options = {}, &block) ⇒ Object



10
11
12
13
# File 'lib/pace.rb', line 10

def self.start(options = {}, &block)
  worker = Pace::Worker.new(options)
  worker.start(&block)
end