Class: HireFire::Initializer

Inherits:
Object
  • Object
show all
Defined in:
lib/hirefire/initializer.rb

Class Method Summary collapse

Class Method Details

.initialize!nil

Note:

Either the Delayed Job, or the Resque worker library must be loaded BEFORE HireFire initializes, otherwise it’ll be unable to detect the proper library and it will not work.

Loads the HireFire extension in to the loaded worker library and extends that library by injecting HireFire hooks in the proper locations.

Currently it supports:

- Delayed Job
  - ActiveRecord ORM
  - Mongoid ODM
- Resque
  - Redis


23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'lib/hirefire/initializer.rb', line 23

def self.initialize!

  ##
  # Initialize Delayed::Job extensions if Delayed::Job is found
  if defined?(::Delayed)
    ##
    # If DelayedJob is using ActiveRecord, then include
    # HireFire::Environment in to the ActiveRecord Delayed Job Backend
    if defined?(::Delayed::Backend::ActiveRecord::Job)
      ::Delayed::Backend::ActiveRecord::Job.
      send(:include, HireFire::Environment).
      send(:include, HireFire::Backend)
    end

    ##
    # If DelayedJob is using Mongoid, then include
    # HireFire::Environment in to the Mongoid Delayed Job Backend
    if defined?(::Delayed::Backend::Mongoid::Job)
      ::Delayed::Backend::Mongoid::Job.
      send(:include, HireFire::Environment).
      send(:include, HireFire::Backend)
    end

    ##
    # Load Delayed Job extensions, this will patch Delayed::Worker
    # to implement the necessary hooks to invoke HireFire from
    require 'hirefire/workers/delayed_job'
  end

  ##
  # Initialize Resque extensions if Resque is found
  if defined?(::Resque)

    ##
    # Include the HireFire::Environment which will add an instance
    # of HireFire::Environment::(Heroku|Local|Noop) to the Resque::Job.environment class method
    #
    # Extend the Resque::Job class with the Resque::Job.jobs class method
    ::Resque::Job.
    send(:include, HireFire::Environment).
    send(:extend, HireFire::Backend::Resque::Redis)

    ##
    # Load Resque extensions, this will patch Resque, Resque::Job and Resque::Worker
    # to implement the necessary hooks to invoke HireFire from
    require 'hirefire/workers/resque'
  end
end