rbbt-rest 1.3.9 → 1.3.10

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
  SHA1:
3
- metadata.gz: 27fb73d8f78ef62a68182c55e631b6d70c508d8e
4
- data.tar.gz: a12b4c60cc6759a36de87af95783eb71362b98ca
3
+ metadata.gz: f37a8c9910018bf272558a676de7eec240f0af66
4
+ data.tar.gz: 5b0b9d2405a59d8c0f134de26368d73d2c0a677c
5
5
  SHA512:
6
- metadata.gz: 197d4db15e3b84632e8370f578aada3f6930d3126cf623a55da1f4c6861009796ccfbe1da1e41f215c9d3fce2c1ee9546b78cf09802dd309da3ba5e79cd188ed
7
- data.tar.gz: 8cebd8b14a008b30705dc15f2471668271cb5712ede4deec16687f18cce6bd0c9ca6c56838813906762ff75b111543e7c2507c114d0e4b2d255c170197d1afcc
6
+ metadata.gz: 5ba5ce4ffd9f48cba52301a48d5510455711b481709bbff517b58f4418ef2fe5ecf01ce6487c0a3acc49227b1e8cbc5284ee6fb213034e55f0a1695c726878d1
7
+ data.tar.gz: b9a3df738c931583e0fe7cf06e08c65d9915ddad0ca6649eef7d0f37616e53ae3ea7fe333bce8571086a67c5148fa5b08642add26979f0d2204d0cc5f59f2123
@@ -13,6 +13,7 @@ class WorkflowRESTClient
13
13
  end
14
14
  def initialize(base_url, task = nil, base_name = nil, inputs = nil, result_type = nil, result_description = nil, is_exec = false)
15
15
  @base_url, @task, @base_name, @inputs, @result_type, @result_description, @is_exec = base_url, task, base_name, inputs, result_type, result_description, is_exec
16
+ @mutex = Mutex.new
16
17
  RemoteStep.get_streams @inputs
17
18
  end
18
19
 
@@ -86,10 +87,13 @@ class WorkflowRESTClient
86
87
  def get
87
88
  params ||= {}
88
89
  params = params.merge(:_format => [:string, :boolean, :tsv, :annotations,:array].include?(result_type.to_sym) ? :raw : :json )
89
- begin
90
- WorkflowRESTClient.get_raw(url, params)
91
- rescue => e
92
- raise e.response
90
+ Misc.insist 3, rand(2) + 1 do
91
+ begin
92
+ WorkflowRESTClient.get_raw(url, params)
93
+ rescue
94
+ Log.exception $!
95
+ raise $!
96
+ end
93
97
  end
94
98
  end
95
99
 
@@ -118,10 +122,18 @@ class WorkflowRESTClient
118
122
  end
119
123
 
120
124
  def run(noload = false)
121
- return exec_job if @is_exec
122
- init_job(:synchronous)
123
- return self.load unless noload
124
- self.load
125
+ @mutex.synchronize do
126
+ @result ||= begin
127
+ if @is_exec
128
+ exec_job
129
+ else
130
+ init_job(:synchronous)
131
+ iii url
132
+ self.load
133
+ end
134
+ end
135
+ end
136
+ noload ? path : @result
125
137
  end
126
138
 
127
139
  def exec(*args)
@@ -129,6 +141,7 @@ class WorkflowRESTClient
129
141
  end
130
142
 
131
143
  def join
144
+ return if self.done?
132
145
  self.load
133
146
  self
134
147
  end
@@ -7,6 +7,7 @@ require 'sinatra/base'
7
7
  require 'sinatra/cross_origin'
8
8
  require 'json'
9
9
 
10
+ require 'rack/stream'
10
11
  module Sinatra
11
12
  module RbbtRESTMain
12
13
  def add_sass_load_path(path)
@@ -44,7 +45,15 @@ module Sinatra
44
45
  set :allow_headers, ['URI']
45
46
 
46
47
  before do
47
- Log.info{ "#{request.request_method} #{request.ip}: " << request.path_info << ". Params: " << Misc.fingerprint(params) }
48
+ method = request.request_method
49
+ method_color = case method
50
+ when "GET"
51
+ :cyan
52
+ when "POST"
53
+ :yellow
54
+ end
55
+
56
+ Log.info{ "#{Log.color method_color, method} #{Log.color(:blue, request.ip)}: " << request.path_info.gsub('/', Log.color(:blue, "/")) << ". Params: " << Log.color(:blue, Misc.fingerprint(params))}
48
57
  process_common_parameters
49
58
 
50
59
  headers 'Access-Control-Allow-Origin' => '*'
@@ -55,7 +64,26 @@ module Sinatra
55
64
  end
56
65
 
57
66
  after do
58
- Log.info{ "#{request.request_method} #{request.ip}: " << request.path_info << ". Status: " << response.status.to_s }
67
+ method = request.request_method
68
+ method_color = case method
69
+ when "GET"
70
+ :cyan
71
+ when "POST"
72
+ :green
73
+ end
74
+
75
+ status = response.status.to_s
76
+ case status.to_i
77
+ when 200
78
+ color = :green
79
+ when 202
80
+ color = :yellow
81
+ when 404,500
82
+ color = :red
83
+ else
84
+ color = nil
85
+ end
86
+ Log.info{ "#{Log.color method_color, method} #{Log.color :blue, request.ip}: " << request.path_info.gsub('/', Log.color(:blue, "/")) << ". Status: " << Log.color(color, status) }
59
87
 
60
88
  if profile
61
89
  result = RubyProf.stop
@@ -144,5 +172,6 @@ module Sinatra
144
172
  end
145
173
  end
146
174
  end
175
+ #use Rack::Stream
147
176
  end
148
177
 
@@ -146,6 +146,7 @@ module Sinatra
146
146
  done = job.done?
147
147
  error = job.error?
148
148
 
149
+ iii [:get, job.path, started, done, error]
149
150
  if done
150
151
  show_result job, workflow, task
151
152
  else
@@ -152,15 +152,25 @@ module WorkflowRESTHelpers
152
152
  job.recursive_clean if update == :recursive_clean
153
153
 
154
154
  execution_type = execution_type(workflow, task)
155
- case execution_type
155
+ case execution_type.to_sym
156
156
  when :exec
157
157
  show_exec_result job.exec, workflow, task
158
158
  when :synchronous, :sync
159
- job.clean if update == :reload
159
+ if update == :reload
160
+ job.abort
161
+ job.clean
162
+ end
163
+
160
164
  begin
161
- job.run unless File.exists? job.info_file
165
+ job.run unless Open.exists? job.info_file
162
166
  job_url = to(File.join("/", workflow.to_s, task, job.name))
163
167
  job_url += "?_format=#{@format}" if @format
168
+ begin
169
+ Misc.insist [0.1, 0.2, 0.5, 1, 3] do
170
+ raise unless Open.exists? job.info_file
171
+ end
172
+ rescue
173
+ end
164
174
  halt 200, job.name if format == :jobname
165
175
  redirect job_url
166
176
  rescue
@@ -168,10 +178,15 @@ module WorkflowRESTHelpers
168
178
  halt 500, $!.message
169
179
  end
170
180
  when :asynchronous, :async, nil
171
- job.clean if update == :reload
181
+ if update == :reload
182
+ job.abort
183
+ job.clean
184
+ end
172
185
 
173
186
  begin
174
- job.fork unless File.exists? job.info_file
187
+ iii :fork
188
+
189
+ job.fork
175
190
 
176
191
  job_url = to(File.join("/", workflow.to_s, task, job.name))
177
192
  job_url += "?_format=#{@format}" if @format
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rbbt-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.9
4
+ version: 1.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Miguel Vazquez
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-04-05 00:00:00.000000000 Z
11
+ date: 2014-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake