Class: Larrow::Runner::Manager
- Inherits:
-
Object
- Object
- Larrow::Runner::Manager
- Includes:
- Service
- Defined in:
- lib/larrow/runner/manager.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
Returns the value of attribute app.
-
#vcs ⇒ Object
Returns the value of attribute vcs.
Class Method Summary collapse
Instance Method Summary collapse
- #build_image ⇒ Object
- #build_server ⇒ Object
- #debug? ⇒ Boolean
- #go ⇒ Object
- #handle_exception ⇒ Object
-
#initialize(target_url) ⇒ Manager
constructor
A new instance of Manager.
- #keep? ⇒ Boolean
- #release ⇒ Object
- #signal_trap ⇒ Object
- #store_resource ⇒ Object
Constructor Details
Instance Attribute Details
#app ⇒ Object
Returns the value of attribute app.
10 11 12 |
# File 'lib/larrow/runner/manager.rb', line 10 def app @app end |
#vcs ⇒ Object
Returns the value of attribute vcs.
9 10 11 |
# File 'lib/larrow/runner/manager.rb', line 9 def vcs @vcs end |
Class Method Details
.cleanup ⇒ Object
101 102 103 104 105 106 107 |
# File 'lib/larrow/runner/manager.rb', line 101 def self.cleanup resource_iterator do |clazz, array| clazz.cleanup array end File.delete ResourcePath rescue nil RunLogger.title 'resource cleaned' end |
.resource ⇒ Object
94 95 96 97 98 99 |
# File 'lib/larrow/runner/manager.rb', line 94 def self.resource resource_iterator do |clazz, array| RunLogger.info clazz.name.split("::").last clazz.show array, 1 end end |
.resource_iterator ⇒ Object
109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/larrow/runner/manager.rb', line 109 def self.resource_iterator RunLogger.title "load resource from #{ResourcePath}" resource = YAML.load(File.read ResourcePath) rescue {} resource.each_pair do |k,array| case k when :nodes yield Model::Node, array end end RunLogger.detail "no resource on the file" if resource.empty? end |
Instance Method Details
#build_image ⇒ Object
32 33 34 35 36 37 |
# File 'lib/larrow/runner/manager.rb', line 32 def build_image handle_exception do app.allocate app.build_image end end |
#build_server ⇒ Object
39 40 41 42 43 44 |
# File 'lib/larrow/runner/manager.rb', line 39 def build_server handle_exception do app.allocate app.deploy end end |
#debug? ⇒ Boolean
70 71 72 |
# File 'lib/larrow/runner/manager.rb', line 70 def debug? RunOption.key? :debug end |
#go ⇒ Object
25 26 27 28 29 30 |
# File 'lib/larrow/runner/manager.rb', line 25 def go handle_exception do app.allocate app.action :all end end |
#handle_exception ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/larrow/runner/manager.rb', line 46 def handle_exception yield rescue InvalidConfigFile => e data = eval(e.) url = "https://github.com/fsword/larrow-runner/wiki/#{data[:wiki]}" RunLogger.err "invalid config file: #{data[:file]}" RunLogger.level(1).err "see: #{url}" rescue => e RunOption[:keep] = true if e.is_a?(ExecutionError) if e.is_a?(ExecutionError) && !debug? data = eval(e.) RunLogger.level(1).err "Execute fail: #{data[:status]}" RunLogger.level(1).err "-> #{data[:errmsg]}" else debug? ? binding.pry : raise(e) end ensure if keep? store_resource else release end end |
#keep? ⇒ Boolean
74 75 76 |
# File 'lib/larrow/runner/manager.rb', line 74 def keep? RunOption.key? :keep end |
#release ⇒ Object
84 85 86 87 88 89 90 91 92 |
# File 'lib/larrow/runner/manager.rb', line 84 def release RunLogger.title 'release resource' begin_at = Time.new if app && app.node app.node.destroy if @state != :release end during = sprintf('%.2f', Time.new - begin_at) RunLogger.level(1).detail "released(#{during}s)" end |
#signal_trap ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/larrow/runner/manager.rb', line 17 def signal_trap trap('INT') do RunLogger.title 'try to release' release ::Kernel.exit end end |
#store_resource ⇒ Object
78 79 80 81 82 |
# File 'lib/larrow/runner/manager.rb', line 78 def store_resource resource = app.dump File.write ResourcePath, YAML.dump(resource) RunLogger.title 'store resource' end |