singularity-cli 0.3.0 → 0.3.1
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 +4 -4
- data/lib/singularity.rb +56 -23
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ad0f8767080ab7ba91d8a934f7db17ebd2fa23e4
|
4
|
+
data.tar.gz: 41704c0d0db1765d77bd86fa38d7c79cdc2eb132
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90b4cd647f164706d0fb3704cada223c00e63d47ecff5ee944f0cc5dfb82a86f277194ad9d46ee79fcc1b1f999af9db8ad8e61fec6af3d201dd592f15c11d48d
|
7
|
+
data.tar.gz: 9db0a3293d747a622c0980160e2d1334871d49f4621cf07cbe98f661cf16a649dd713ead2d3a14f40f86ed3f4877f2e5ac8c9c727ad4d468c1b0395d337d6698
|
data/lib/singularity.rb
CHANGED
@@ -178,8 +178,7 @@ module Singularity
|
|
178
178
|
# get active tasks until ours shows up so we can get IP/PORT
|
179
179
|
begin
|
180
180
|
@thisTask = ''
|
181
|
-
@tasks = RestClient.get "#{@uri}/api/tasks/active", :content_type => :json
|
182
|
-
@tasks = JSON.parse(@tasks)
|
181
|
+
@tasks = JSON.parse(RestClient.get "#{@uri}/api/tasks/active", :content_type => :json)
|
183
182
|
@tasks.each do |entry|
|
184
183
|
if entry['taskRequest']['request']['id'] == @data['requestId']
|
185
184
|
@thisTask = entry
|
@@ -195,31 +194,65 @@ module Singularity
|
|
195
194
|
# this makes sure that the docker image has completely started and the SSH command succeeds
|
196
195
|
where = Dir.pwd.split('/').last
|
197
196
|
puts " Opening a shell to #{where}, please wait a moment...".light_blue
|
198
|
-
puts " STDOUT / STDERR will print to console when session is over.".light_blue
|
199
197
|
begin end until system "ssh -o LogLevel=quiet -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no root@#{@ip} -p #{@port}"
|
200
198
|
else
|
201
199
|
puts " Deployed and running #{@data['command']} #{@data['arguments']}".light_green
|
202
|
-
|
200
|
+
print " STDOUT".light_cyan
|
201
|
+
print " and"
|
202
|
+
print " STDERR".light_magenta
|
203
|
+
puts ":"
|
203
204
|
|
204
|
-
|
205
|
-
|
206
|
-
@
|
207
|
-
@
|
208
|
-
@
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
205
|
+
# output STDOUT / STDERR to shell
|
206
|
+
@stdoutOffset = 0
|
207
|
+
@stderrOffset = 0
|
208
|
+
@lastOutLine = ''
|
209
|
+
@lastErrLine = ''
|
210
|
+
begin
|
211
|
+
# get most recent task state
|
212
|
+
@taskState = JSON.parse(RestClient.get "#{@uri}/api/history/task/#{@thisTask['taskId']['id']}")
|
213
|
+
@taskState["taskUpdates"].each do |update|
|
214
|
+
@taskState = update['taskState']
|
215
|
+
end
|
216
|
+
|
217
|
+
# need to wait for "task_running" before we can ask for STDOUT/STDERR
|
218
|
+
if @taskState == "TASK_RUNNING"
|
219
|
+
@stdout = JSON.parse(RestClient.get "#{@uri}/api/sandbox/#{@thisTask['taskId']['id']}/read", {params: {path: "stdout", length: 30000, offset: @stdoutOffset}})['data']
|
220
|
+
@stdoutOffset += @stdout.length
|
221
|
+
@stdout = @stdout.split("\n")
|
222
|
+
if @stdout.any?
|
223
|
+
if @lastOutLine.include? @stdout[0]
|
224
|
+
@stdout.shift
|
225
|
+
end
|
226
|
+
if !@stdout.empty?
|
227
|
+
if @stdout[0].length > 0
|
228
|
+
@stdout.each do |i|
|
229
|
+
puts i.light_cyan
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
@lastOutLine = @stdout.last
|
234
|
+
end
|
235
|
+
|
236
|
+
@stderr = JSON.parse(RestClient.get "#{@uri}/api/sandbox/#{@thisTask['taskId']['id']}/read", {params: {path: "stderr", length: 30000, offset: @stderrOffset}})['data']
|
237
|
+
@stderrOffset += @stderr.length
|
238
|
+
@stderr = @stderr.split("\n")
|
239
|
+
if @stderr.any?
|
240
|
+
if @lastErrLine.include? @stderr[0]
|
241
|
+
@stderr.shift
|
242
|
+
end
|
243
|
+
if !@stderr.empty?
|
244
|
+
if @stderr[0].length > 0
|
245
|
+
@stderr.each do |i|
|
246
|
+
puts i.light_magenta
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
@lastErrLine = @stderr.last
|
251
|
+
end
|
252
|
+
|
253
|
+
end
|
254
|
+
end until @taskState == "TASK_FINISHED"
|
255
|
+
end
|
223
256
|
|
224
257
|
# finally, delete the request (which also deletes the corresponding task)
|
225
258
|
RestClient.delete "#{@uri}/api/requests/request/#{@data['requestId']}"
|