make config reading a global thing
This commit is contained in:
parent
06387cb1e6
commit
0685b5436f
|
@ -0,0 +1,21 @@
|
|||
module Hydra
|
||||
class Config
|
||||
class << self
|
||||
def load(config_file)
|
||||
begin
|
||||
config_erb = ERB.new(IO.read(config_file)).result(binding)
|
||||
rescue Exception => e
|
||||
raise(YmlLoadError,"config file was found, but could not be parsed with ERB.\n#{$!.inspect}")
|
||||
end
|
||||
|
||||
begin
|
||||
config_yml = YAML::load(config_erb)
|
||||
rescue StandardError => e
|
||||
raise(YmlLoadError,"config file was found, but could not be parsed.\n#{$!.inspect}")
|
||||
end
|
||||
|
||||
config_yml
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -1,4 +1,5 @@
|
|||
require 'hydra/hash'
|
||||
require 'hydra/config'
|
||||
require 'open3'
|
||||
require 'hydra/tmpdir'
|
||||
require 'erb'
|
||||
|
@ -37,18 +38,7 @@ module Hydra #:nodoc:
|
|||
opts.stringify_keys!
|
||||
config_file = opts.delete('config') { nil }
|
||||
if config_file
|
||||
|
||||
begin
|
||||
config_erb = ERB.new(IO.read(config_file)).result(binding)
|
||||
rescue Exception => e
|
||||
raise(YmlLoadError,"config file was found, but could not be parsed with ERB.\n#{$!.inspect}")
|
||||
end
|
||||
|
||||
begin
|
||||
config_yml = YAML::load(config_erb)
|
||||
rescue StandardError => e
|
||||
raise(YmlLoadError,"config file was found, but could not be parsed.\n#{$!.inspect}")
|
||||
end
|
||||
config_yml = Hydra::Config.load(config_file)
|
||||
|
||||
opts.merge!(config_yml.stringify_keys!)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require 'yaml'
|
||||
require 'hydra/config'
|
||||
|
||||
module Hydra #:nodoc:
|
||||
# Hydra class responsible for delegate work down to workers.
|
||||
#
|
||||
|
@ -62,7 +64,8 @@ module Hydra #:nodoc:
|
|||
opts.stringify_keys!
|
||||
config_file = opts.delete('config') { nil }
|
||||
if config_file
|
||||
opts.merge!(YAML.load_file(config_file).stringify_keys!)
|
||||
config_yml = Hydra::Config.load(config_file)
|
||||
opts.merge!(config_yml.stringify_keys!)
|
||||
end
|
||||
@verbose = opts.fetch('verbose') { false }
|
||||
@sync = opts.fetch('sync') { {} }
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
require 'open3'
|
||||
require 'hydra/config'
|
||||
|
||||
module Hydra #:nodoc:
|
||||
# Hydra Task Common attributes and methods
|
||||
class Task
|
||||
|
@ -227,7 +229,6 @@ module Hydra #:nodoc:
|
|||
# t.verbose = false # optionally set to true for lots of debug messages
|
||||
# end
|
||||
class SyncTask < Hydra::Task
|
||||
|
||||
# Create a new SyncTestTask
|
||||
def initialize(name = :sync)
|
||||
@name = name
|
||||
|
@ -280,7 +281,7 @@ module Hydra #:nodoc:
|
|||
def define
|
||||
desc "Run #{@name} remotely on all workers"
|
||||
task "hydra:remote:#{@name}" do
|
||||
config = YAML.load_file(@config)
|
||||
config = Hydra::Config.load(@config)
|
||||
environment = config.fetch('environment') { 'test' }
|
||||
workers = config.fetch('workers') { [] }
|
||||
workers = workers.select{|w| w['type'] == 'ssh'}
|
||||
|
|
Loading…
Reference in New Issue