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 +4 -4
- data/app/models/command_proposal/iteration.rb +4 -0
- data/app/models/command_proposal/service/proposal_presenter.rb +1 -0
- data/app/views/command_proposal/tasks/_lines.html.erb +1 -1
- data/lib/command_proposal/services/runner.rb +24 -16
- data/lib/command_proposal/services/shut_down.rb +1 -1
- data/lib/command_proposal/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43e714b8d84f486d67fabcf4d171cc38f6fe3e97c1e4cd776b558ef9feef2bb0
|
4
|
+
data.tar.gz: 5107629d432ed32fb26bd3fbfe56094287b1a9a0eb2feaf72b1e9f493b3d1dfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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")
|
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.
|
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
|
-
|
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
|
-
|
119
|
-
|
120
|
-
while running_thread.status.present?
|
121
|
-
@iteration.reload
|
118
|
+
}
|
122
119
|
|
123
|
-
|
124
|
-
|
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
|
-
|
128
|
-
|
129
|
-
status = :cancelled
|
130
|
-
end
|
127
|
+
while running_thread.status.present?
|
128
|
+
@iteration.reload
|
131
129
|
|
132
|
-
|
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
|
16
|
+
terminated_result = "#{iteration&.result}\n\n~~~~~ TERMINATED ~~~~~"
|
17
17
|
iteration.update(
|
18
18
|
status: :terminated,
|
19
19
|
result: terminated_result,
|
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.
|
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-
|
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.
|
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
|