Class: MotherBrain::CommandInvoker
- Inherits:
-
Object
- Object
- MotherBrain::CommandInvoker
- Includes:
- Celluloid, MB::Mixin::Locks, MB::Mixin::Services, Logging
- Defined in:
- lib/mb/command_invoker.rb,
lib/mb/command_invoker/worker.rb
Defined Under Namespace
Classes: Worker
Class Method Summary collapse
Instance Method Summary collapse
-
#async_invoke(command_name, options = {}) ⇒ MB::Job
Asynchronously invoke a command on a plugin or a component of a plugin.
-
#find(command_name, plugin_name, options = {}) ⇒ MB::Command
Find a plugin or component level which has already been loaded by a plugin.
-
#initialize ⇒ CommandInvoker
constructor
A new instance of CommandInvoker.
-
#invoke(job, command_name, options = {}) ⇒ Boolean
Invoke a command on a plugin or a component of a plugin.
Methods included from Logging
add_argument_header, dev, filename, #log_exception, logger, #logger, reset, set_logger, setup
Constructor Details
#initialize ⇒ CommandInvoker
Returns a new instance of CommandInvoker.
21 22 23 |
# File 'lib/mb/command_invoker.rb', line 21 def initialize log.debug { "Command Invoker starting..." } end |
Class Method Details
.instance ⇒ Celluloid::Actor(CommandInvoker)
9 10 11 |
# File 'lib/mb/command_invoker.rb', line 9 def instance MB::Application[:command_invoker] or raise Celluloid::DeadActorError, "command invoker not running" end |
Instance Method Details
#async_invoke(command_name, options = {}) ⇒ MB::Job
Asynchronously invoke a command on a plugin or a component of a plugin.
38 39 40 41 42 |
# File 'lib/mb/command_invoker.rb', line 38 def async_invoke(command_name, = {}) job = Job.new(:command) async(:invoke, job, command_name, ) job.ticket end |
#find(command_name, plugin_name, options = {}) ⇒ MB::Command
Find a plugin or component level which has already been loaded by a plugin.
68 69 70 71 72 73 74 75 76 |
# File 'lib/mb/command_invoker.rb', line 68 def find(command_name, plugin_name, = {}) if [:version] for_version([:version], command_name, plugin_name, [:component]) elsif [:environment] for_environment([:environment], command_name, plugin_name, [:component]) else find_latest(command_name, plugin_name, [:component]) end end |
#invoke(job, command_name, options = {}) ⇒ Boolean
Invoke a command on a plugin or a component of a plugin
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 |
# File 'lib/mb/command_invoker.rb', line 96 def invoke(job, command_name, = {}) = .reverse_merge(arguments: Array.new, force: false) job.report_running if [:plugin].nil? job.report_failure MB::ArgumentError.new("must specify a plugin that the command belongs to") return false end if [:environment].nil? job.report_failure MB::ArgumentError.new("must specify an environment to run this command on") return false end job.set_status("Finding environment #{[:environment]}") environment_manager.find([:environment]) command = find(command_name, [:plugin], .slice(:component, :environment, :version)) worker = Worker.new(command, [:environment], [:node_filter]) chef_synchronize(chef_environment: [:environment], force: [:force], job: job) do worker.run(job, [:arguments]) end job.report_success("successfully executed command") true rescue => ex job.report_failure(ex) false ensure job.terminate if job && job.alive? worker.terminate if worker && worker.alive? end |