command_proposal 1.0.15 → 1.0.16

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 321b3627d2af7cf183da1cd1071775e7f13907b0fda6101acce253f9649f8a42
4
- data.tar.gz: c9a30e58a53bb372807e05e765a7b92368433ced38325e8d7800e9f6b983eeb8
3
+ metadata.gz: 43e714b8d84f486d67fabcf4d171cc38f6fe3e97c1e4cd776b558ef9feef2bb0
4
+ data.tar.gz: 5107629d432ed32fb26bd3fbfe56094287b1a9a0eb2feaf72b1e9f493b3d1dfd
5
5
  SHA512:
6
- metadata.gz: ddcd08648f107fb5e50c57ae46a7ff93ddb1f7e79ea900e7a052afd6fb31574fd85fae1bf4a2214313a6fae8b46d79e4406d2be6756714319d928c259b612557
7
- data.tar.gz: 629c1bc1f60e363396a7672122dc0a945c042baed8c43339fbc5ae7d80cb71aa645de0d3c199709d923cc1c1376e3d305b273ef3f71275ae53215899e59e3ef1
6
+ metadata.gz: 283e95ed280a541f6e607e2802068664244d532186448cafe42850763bb318159335b33b64e5411c729a65cbd427de94b6e672154efe0231487a71ba8023e659
7
+ data.tar.gz: bbece28324234cfee33481dbdeef5fdadd0b90ff982bb3eeabeaa76e6732c558298ed8dd7a0e313f9304b574dc7559e13187c4bdc3e7cec0a3ed7c0c85102e9c
@@ -65,6 +65,10 @@ class ::CommandProposal::Iteration < ApplicationRecord
65
65
  task.primary_iteration == self
66
66
  end
67
67
 
68
+ def approved?
69
+ super || (session_type == "function" && approved_at?)
70
+ end
71
+
68
72
  def complete?
69
73
  success? || failed? || cancelled? || terminated?
70
74
  end
@@ -13,6 +13,7 @@ module CommandProposal
13
13
  delegate :description, to: :iteration
14
14
  delegate :args, to: :iteration
15
15
  delegate :code, to: :iteration
16
+ delegate :result, to: :iteration
16
17
  delegate :status, to: :iteration
17
18
  delegate :approved_at, to: :iteration
18
19
  delegate :started_at, to: :iteration
@@ -1,5 +1,5 @@
1
1
  <% if lines.blank? && !(skip_empty ||= false) -%><div class="line"></div><% end
2
- -%><% lines&.split("\n").each do |line|
2
+ -%><% lines&.split("\n")&.each do |line|
3
3
  truncate = ::CommandProposal::Iteration::TRUNCATE_COUNT
4
4
  -%><div class="line"><%= line.truncate(truncate) -%></div><%=
5
5
  if line.length > truncate
@@ -65,7 +65,7 @@ module CommandProposal
65
65
  end
66
66
 
67
67
  def quick_run(friendly_id)
68
- task = ::CommandProposal::Task.module.find_by!(friendly_id: friendly_id)
68
+ task = ::CommandProposal::Task.find_by!(friendly_id: friendly_id)
69
69
  iteration = task&.primary_iteration
70
70
 
71
71
  raise CommandProposal::Error, ":#{friendly_id} does not have approval to run." unless iteration&.approved?
@@ -98,12 +98,12 @@ module CommandProposal
98
98
  return @iteration.result = results_from_exception(e)
99
99
  end
100
100
 
101
- stored_stdout = $stdout
102
- $stdout = StringIO.new
101
+ stored_stdout = $stdout # quiet
102
+ $stdout = StringIO.new # quiet
103
103
  result = nil # Init var for scope
104
104
  status = nil
105
105
 
106
- running_thread = Thread.new do
106
+ runner_proc = proc {
107
107
  begin
108
108
  # Run `bring` functions in here so we can capture any string outputs
109
109
  # OR! Run the full runner and instead of saving to an iteration, return the string for prepending here
@@ -115,28 +115,36 @@ module CommandProposal
115
115
 
116
116
  result = results_from_exception(e)
117
117
  end
118
- end
119
-
120
- while running_thread.status.present?
121
- @iteration.reload
118
+ }
122
119
 
123
- if $stdout.try(:string) != @iteration.result
124
- @iteration.update(result: $stdout.try(:string).dup)
120
+ if Rails.application.config.active_job&.queue_adapter == :inline
121
+ runner_proc.call
122
+ else
123
+ running_thread = Thread.new do
124
+ runner_proc.call
125
125
  end
126
126
 
127
- if @iteration.cancelling?
128
- running_thread.exit
129
- status = :cancelled
130
- end
127
+ while running_thread.status.present?
128
+ @iteration.reload
131
129
 
132
- sleep 0.4
130
+ if $stdout.try(:string) != @iteration.result
131
+ @iteration.update(result: $stdout.try(:string).dup)
132
+ end
133
+
134
+ if @iteration.cancelling?
135
+ running_thread.exit
136
+ status = :cancelled
137
+ end
138
+
139
+ sleep 0.4
140
+ end
133
141
  end
134
142
 
135
143
  output = $stdout.try(:string)
136
144
  output = nil if output == ""
137
145
  # Not using presence because we want to maintain other empty objects such as [] and {}
138
146
 
139
- $stdout = stored_stdout
147
+ $stdout = stored_stdout # quiet
140
148
  @iteration.status = status
141
149
  @iteration.result = [output, result].compact.join("\n")
142
150
  end
@@ -13,7 +13,7 @@ module CommandProposal
13
13
  def terminate(iteration)
14
14
  return unless iteration.running?
15
15
 
16
- terminated_result = iteration.result + "\n\n~~~~~ TERMINATED ~~~~~"
16
+ terminated_result = "#{iteration&.result}\n\n~~~~~ TERMINATED ~~~~~"
17
17
  iteration.update(
18
18
  status: :terminated,
19
19
  result: terminated_result,
@@ -1,3 +1,3 @@
1
1
  module CommandProposal
2
- VERSION = "1.0.15"
2
+ VERSION = "1.0.16"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: command_proposal
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.15
4
+ version: 1.0.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rocco Nicholls
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-03-05 00:00:00.000000000 Z
11
+ date: 2022-03-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -162,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
162
162
  - !ruby/object:Gem::Version
163
163
  version: '0'
164
164
  requirements: []
165
- rubygems_version: 3.2.22
165
+ rubygems_version: 3.2.3
166
166
  signing_key:
167
167
  specification_version: 4
168
168
  summary: Gives the ability to run approved commands through a UI in your browser