smart_proxy_dynflow 0.8.1 → 0.9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c9cd93e1cf950c5f7977d700a2d8b307faa98182af93063c55ced580617d054
4
- data.tar.gz: 2de7767e855c5914d6db7678ef2c2302c414a20b04cb6dd4df7294263ee00f95
3
+ metadata.gz: 86c46197119a24e70fc65afe7698d99473b5aaaae0eb2b32aed48523a03de021
4
+ data.tar.gz: ea987bf5d6797680a8c37c9e03d4872ad714254624a98195749594febdaddb06
5
5
  SHA512:
6
- metadata.gz: b03995ac1c1bf44c900926371d3b42c56f05dc8b994fb07f3c87613e788a990e9ec597d67bb24a97279ae4bc0557fca01dabfbaace26299553467f8173ff8f73
7
- data.tar.gz: 0d4737d0298d940988c51ba62e04c45740530660ae76c492e706459965446e984f2ddeb319651a416864636dca407d4f281029bb75da9ad747da7f6b6d71ee42
6
+ metadata.gz: b1fdc2770779b35094098506a8178696708a8c207e083fd1c3cd1d148fc63eca35cefdad3698e86f2915919a935ae2c560f7c250251fb1eddf91dd27ebf7e339
7
+ data.tar.gz: fb649ed0bf1c2d7a56f30ff29c5cc718b93832700d109a92740fd43813c0fa73be424eaa0b9d363696e9e4faae45f9bb4d1a5aa2efa5c43ca35032332f13f3eb
@@ -36,7 +36,8 @@ module Proxy
36
36
 
37
37
  post "/tasks/launch/?" do
38
38
  params = MultiJson.load(request.body.read)
39
- launcher = launcher_class(params).new(world, callback_host(params, request), params.fetch('options', {}))
39
+ first_params = params['input']&.values&.first || {}
40
+ launcher = launcher_class(params).new(world, callback_host(first_params, request), params.fetch('options', {}))
40
41
  launcher.launch!(params['input'])
41
42
  launcher.results.to_json
42
43
  end
@@ -59,6 +60,16 @@ module Proxy
59
60
  tasks_count(params['state']).to_json
60
61
  end
61
62
 
63
+ post "/tasks/statuses" do
64
+ params = MultiJson.load(request.body.read)
65
+ ids = params.fetch('task_ids', [])
66
+ if ids.empty?
67
+ status 422
68
+ return { error: "'task_ids' needs to be provided and be a non-empty array of task UUIDs" }
69
+ end
70
+ tasks_statuses(params['task_ids']).to_json
71
+ end
72
+
62
73
  # capturing post "/tasks/:task_id/(update|done)"
63
74
  post TASK_UPDATE_REGEXP_PATH do |task_id, _action|
64
75
  data = MultiJson.load(request.body.read)
@@ -72,8 +83,13 @@ module Proxy
72
83
  private
73
84
 
74
85
  def callback_host(params, request)
75
- params.fetch('action_input', {})['proxy_url'] ||
76
- request.env.values_at('HTTP_X_FORWARDED_FOR', 'HTTP_HOST').compact.first
86
+ params.fetch('action_input', {})['proxy_url'] || callback_host_from_env(request)
87
+ end
88
+
89
+ def callback_host_from_env(request)
90
+ protocol = %w[yes on 1].include?(request.env['HTTPS'].to_s) ? 'https' : 'http'
91
+ host = request.env.values_at('HTTP_X_FORWARDED_FOR', 'HTTP_HOST').compact.first
92
+ "#{protocol}://#{host}"
77
93
  end
78
94
 
79
95
  def launcher_class(params)
@@ -28,8 +28,8 @@ module Proxy::Dynflow
28
28
 
29
29
  db_file = Settings.instance.database
30
30
  if db_file.nil? || db_file.empty?
31
- Log.instance.warn "Could not open DB for dynflow at '#{db_file}', " \
32
- "will keep data in memory. Restart will drop all dynflow data."
31
+ Log.instance.info "Using in-memory database (default behaviour). Restart will drop all dynflow data. " \
32
+ "To change this behaviour configure setting 'database'."
33
33
  else
34
34
  FileUtils.mkdir_p(File.dirname(db_file))
35
35
  db_conn_string += "/#{db_file}"
@@ -1,3 +1,6 @@
1
+ require 'smart_proxy_dynflow/action/external_polling'
2
+ require 'smart_proxy_dynflow/action/runner'
3
+
1
4
  module Proxy
2
5
  module Dynflow
3
6
  module Helpers
@@ -35,16 +38,19 @@ module Proxy
35
38
 
36
39
  def task_status(task_id)
37
40
  ep = world.persistence.load_execution_plan(task_id)
38
- actions = ep.actions.map do |action|
39
- refresh_output(ep, action)
40
- expand_output(action)
41
- end
42
- ep.to_hash.merge(:actions => actions)
41
+ execution_plan_status(ep)
43
42
  rescue KeyError => _e
44
43
  status 404
45
44
  {}
46
45
  end
47
46
 
47
+ def tasks_statuses(task_ids)
48
+ eps = world.persistence.find_execution_plans(filters: { uuid: task_ids })
49
+ eps.reduce({}) do |acc, ep|
50
+ acc.update(ep.id => execution_plan_status(ep))
51
+ end
52
+ end
53
+
48
54
  def tasks_count(state)
49
55
  state ||= 'all'
50
56
  filter = state != 'all' ? { :filters => { :state => [state] } } : {}
@@ -69,6 +75,14 @@ module Proxy
69
75
  hash[:output][:result] = action.output_result if action.is_a?(Proxy::Dynflow::Action::Runner)
70
76
  hash
71
77
  end
78
+
79
+ def execution_plan_status(plan)
80
+ actions = plan.actions.map do |action|
81
+ refresh_output(plan, action)
82
+ expand_output(action)
83
+ end
84
+ plan.to_hash.merge(:actions => actions)
85
+ end
72
86
  end
73
87
  end
74
88
  end
@@ -125,9 +125,15 @@ module Proxy
125
125
  return
126
126
  end
127
127
 
128
+ # Even though the FDs are still open, the child might have exited already
129
+ pid, status = Process.waitpid2(@pid, Process::WNOHANG)
130
+ timeout = 1 if pid
131
+
128
132
  ready_readers, ready_writers = IO.select(readers, writers, nil, timeout)
129
133
  (ready_readers || []).each(&:read_available!)
130
134
  (ready_writers || []).each(&:write_available!)
135
+
136
+ finish(status) if pid
131
137
  end
132
138
 
133
139
  # Sets block to be executed each time data is read from child process' standard output
@@ -156,11 +162,13 @@ module Proxy
156
162
  # Makes the process manager finish its run, closing opened FDs and reaping the child process
157
163
  #
158
164
  # @return [void]
159
- def finish
165
+ def finish(status = nil)
160
166
  close
161
- unless @pid == -1
167
+ if status.nil? && @pid != -1 && !done?
162
168
  _pid, status = Process.wait2(@pid)
163
169
  @status = status.exitstatus
170
+ elsif status
171
+ @status = status.exitstatus
164
172
  end
165
173
  end
166
174
  end
@@ -1,5 +1,5 @@
1
1
  module Proxy
2
2
  module Dynflow
3
- VERSION = '0.8.1'.freeze
3
+ VERSION = '0.9.0'.freeze
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_proxy_dynflow
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.1
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ivan Nečas
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 1980-01-01 00:00:00.000000000 Z
11
+ date: 2022-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dynflow
@@ -208,7 +208,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
208
208
  - !ruby/object:Gem::Version
209
209
  version: '0'
210
210
  requirements: []
211
- rubygems_version: 3.2.26
211
+ rubygems_version: 3.3.20
212
212
  signing_key:
213
213
  specification_version: 4
214
214
  summary: Dynflow runtime for Foreman smart proxy