Module: Proxy::Dynflow::Helpers
- Defined in:
- lib/smart_proxy_dynflow/helpers.rb
Instance Method Summary collapse
- #authorize_with_token(task_id:, clear: true) ⇒ Object
- #cancel_task(task_id) ⇒ Object
- #dispatch_external_event(task_id, params) ⇒ Object
- #execution_plan_status(plan) ⇒ Object
- #expand_output(action) ⇒ Object
- #refresh_output(execution_plan, action) ⇒ Object
- #task_status(task_id) ⇒ Object
- #tasks_count(state) ⇒ Object
- #tasks_statuses(task_ids) ⇒ Object
- #trigger_task(*args) ⇒ Object
- #world ⇒ Object
Instance Method Details
#authorize_with_token(task_id:, clear: true) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 13 def (task_id:, clear: true) if request.env.key? 'HTTP_AUTHORIZATION' if defined?(::Proxy::Dynflow) auth = request.env['HTTP_AUTHORIZATION'] basic_prefix = /\ABasic / if !auth.to_s.empty? && auth =~ basic_prefix && Proxy::Dynflow::OtpManager.authenticate(auth.gsub(basic_prefix, ''), expected_user: task_id, clear: clear) Log.instance.debug('authorized with token') return true end end halt 403, MultiJson.dump(:error => 'Invalid username or password supplied') end false end |
#cancel_task(task_id) ⇒ Object
35 36 37 38 39 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 35 def cancel_task(task_id) execution_plan = world.persistence.load_execution_plan(task_id) cancel_events = execution_plan.cancel { :task_id => task_id, :canceled_steps_count => cancel_events.size } end |
#dispatch_external_event(task_id, params) ⇒ Object
63 64 65 66 67 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 63 def dispatch_external_event(task_id, params) world.event(task_id, params['step_id'].to_i, ::Proxy::Dynflow::Runner::ExternalEvent.new(params)) end |
#execution_plan_status(plan) ⇒ Object
81 82 83 84 85 86 87 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 81 def execution_plan_status(plan) actions = plan.actions.map do |action| refresh_output(plan, action) (action) end plan.to_hash.merge(:actions => actions) end |
#expand_output(action) ⇒ Object
75 76 77 78 79 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 75 def (action) hash = action.to_hash hash[:output][:result] = action.output_result if action.is_a?(Proxy::Dynflow::Action::Runner) hash end |
#refresh_output(execution_plan, action) ⇒ Object
69 70 71 72 73 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 69 def refresh_output(execution_plan, action) if action.is_a?(Proxy::Dynflow::Action::WithExternalPolling) && %i[running suspended].include?(action.run_step&.state) world.event(execution_plan.id, action.run_step_id, Proxy::Dynflow::Action::WithExternalPolling::Poll) end end |
#task_status(task_id) ⇒ Object
41 42 43 44 45 46 47 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 41 def task_status(task_id) ep = world.persistence.load_execution_plan(task_id) execution_plan_status(ep) rescue KeyError => _e status 404 {} end |
#tasks_count(state) ⇒ Object
56 57 58 59 60 61 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 56 def tasks_count(state) state ||= 'all' filter = state != 'all' ? { :filters => { :state => [state] } } : {} count = world.persistence.find_execution_plan_counts(filter) { :count => count, :state => state } end |
#tasks_statuses(task_ids) ⇒ Object
49 50 51 52 53 54 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 49 def tasks_statuses(task_ids) eps = world.persistence.find_execution_plans(filters: { uuid: task_ids }) eps.reduce({}) do |acc, ep| acc.update(ep.id => execution_plan_status(ep)) end end |
#trigger_task(*args) ⇒ Object
30 31 32 33 |
# File 'lib/smart_proxy_dynflow/helpers.rb', line 30 def trigger_task(*args) triggered = world.trigger(*args) { :task_id => triggered.id } end |