Class: Jobs::Initializer

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

Class Method Summary collapse

Class Method Details

.config {|config| ... } ⇒ Object

Configure client to be selective about which job servers to send work

Jobs::Initializer.config do|cfg|

cfg[:sphinx] = [ {:host => '192.168.1.102', :port => 4321} ]
cfg[:video_encoder] = [ {:host => '192.168.1.102', :port => 4321} ]

Yields:



29
30
31
32
33
# File 'lib/jobs/initializer.rb', line 29

def self.config
  config = {}
  yield config
  eval %{::Jobs::HostMap=config}
end

.rails!Object



18
19
20
# File 'lib/jobs/initializer.rb', line 18

def self.rails!
  run! "#{RAILS_ROOT}/app/jobs", "#{RAILS_ROOT}/config/jobs.yml", RAILS_ENV
end

.ready?Boolean

Returns:

  • (Boolean)


14
15
16
# File 'lib/jobs/initializer.rb', line 14

def self.ready?
  defined?(::Jobs::Root) and defined?(::Jobs::Keys)
end

.run!(job_root_path, job_config_path, env) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/jobs/initializer.rb', line 6

def self.run!(job_root_path,job_config_path,env)
  ::ActiveRecord::Base.send(:include,Jobs::Scheduler)
  # define the Jobs::Keys constant, e.g. RAILS_ROOT/config/jobs.yml
  eval %{::Jobs::Keys=HashWithIndifferentAccess.new(YAML.load_file(job_config_path)[env])}
  # define the jobs root e.g. RAILS_ROOT/apps/jobs
  eval %{::Jobs::Root=job_root_path}
end

.test!Object



35
36
37
# File 'lib/jobs/initializer.rb', line 35

def self.test!
  run! File.join(File.dirname(__FILE__),'..','..','tests','jobs'), File.join(File.dirname(__FILE__),'..','..','config','jobs.yml'), 'test'
end