Module: HireFire::Environment

Defined in:
lib/hirefire.rb,
lib/hirefire/environment.rb,
lib/hirefire/environment/base.rb,
lib/hirefire/environment/noop.rb,
lib/hirefire/environment/local.rb,
lib/hirefire/environment/heroku.rb

Overview

HireFire::Environment namespace

Defined Under Namespace

Modules: ClassMethods, DelayedJob Classes: Base, Heroku, Local, Noop

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object

This module gets included in either:

- Delayed::Backend::ActiveRecord::Job
- Delayed::Backend::Mongoid::Job
- Resque::Job

One of these classes will then be provided with an instance of one of the following:

- HireFire::Environment::Heroku
- HireFire::Environment::Local
- HireFire::Environment::Noop

This instance is stored in the Class.environment class method

The Delayed Job classes receive 3 hooks:

- hirefire_hire      ( invoked when a job gets queued )
- environment.fire   ( invoked when a queued job gets destroyed )
- environment.fire   ( invoked when a queued job gets updated unless the job didn't fail )

The Resque classes get their hooks injected from the HireFire::Initializer#initialize! method

Parameters:

  • base (Class)

    This is the class in which this module will be included



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hirefire/environment.rb', line 27

def self.included(base)
  base.send :extend, HireFire::Environment::ClassMethods

  ##
  # Only implement these hooks for Delayed::Job backends
  if base.name =~ /Delayed::Backend::(ActiveRecord|Mongoid)::Job/
    base.send :extend, HireFire::Environment::DelayedJob::ClassMethods

    base.class_eval do
      after_create  'self.class.hirefire_hire'
      after_destroy 'self.class.environment.fire'
      after_update  'self.class.environment.fire',
        :unless => Proc.new { |job| job.failed_at.nil? }
    end
  end

  Logger.message("#{ base.name } detected!")
end