Class: Floe::ServiceNow::Runner
- Inherits:
-
BuiltinRunner::Runner
- Object
- BuiltinRunner::Runner
- Floe::ServiceNow::Runner
- Defined in:
- lib/floe/servicenow/runner.rb
Constant Summary collapse
- SCHEME =
"servicenow"- SCHEME_PREFIX =
"#{SCHEME}://".freeze
- API_CLASSES =
{ "cmdb" => Cmdb, "table" => Table, "incident" => Incident, "oauth" => OAuth, "service_catalog" => ServiceCatalog }.freeze
Instance Method Summary collapse
- #cleanup(runner_context) ⇒ Object
- #run_async!(resource, params, secrets, context) ⇒ Object
- #status!(runner_context) ⇒ Object
Instance Method Details
#cleanup(runner_context) ⇒ Object
35 36 37 38 39 40 41 42 43 44 |
# File 'lib/floe/servicenow/runner.rb', line 35 def cleanup(runner_context) method_name = runner_context["method"] raise ArgumentError if method_name.nil? api_class, api_method = resolve_api_method(method_name) cleanup_method = :"#{api_method}_cleanup" return unless api_class.respond_to?(cleanup_method, true) api_class.send(cleanup_method, runner_context) end |
#run_async!(resource, params, secrets, context) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/floe/servicenow/runner.rb', line 16 def run_async!(resource, params, secrets, context) raise ArgumentError, "Invalid resource" unless resource&.start_with?(SCHEME_PREFIX) method_name = resource.sub(SCHEME_PREFIX, "") runner_context = {"method" => method_name} begin api_class, api_method = resolve_api_method(method_name) method_result = api_class.public_send(api_method, params, secrets, context) method_result.merge(runner_context) rescue NoMethodError Floe::ServiceNow.error!(runner_context, :cause => "undefined method [#{method_name}]") rescue => err Floe::ServiceNow.error!(runner_context, :cause => err.to_s) ensure cleanup(runner_context) end end |
#status!(runner_context) ⇒ Object
46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/floe/servicenow/runner.rb', line 46 def status!(runner_context) method_name = runner_context["method"] raise ArgumentError if method_name.nil? return if runner_context["running"] == false api_class, api_method = resolve_api_method(method_name) status_method = :"#{api_method}_status!" return runner_context unless api_class.respond_to?(status_method, true) api_class.send(status_method, runner_context) end |