simple_worker 2.0.0.beta.15 → 2.0.0.beta.16
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.
- data/README.markdown +1 -0
- data/lib/simple_worker/api.rb +29 -22
- data/lib/simple_worker/base.rb +2 -0
- data/lib/simple_worker/config.rb +3 -3
- data/lib/simple_worker/service.rb +3 -14
- metadata +2 -2
data/README.markdown
CHANGED
data/lib/simple_worker/api.rb
CHANGED
@@ -52,7 +52,7 @@ module SimpleWorker
|
|
52
52
|
@port = options[:port] || @config.port || 443
|
53
53
|
@token = options[:token] || @config.token || token
|
54
54
|
@version = options[:version]
|
55
|
-
|
55
|
+
#@logger = options[:logger]
|
56
56
|
|
57
57
|
@base_url = "#{@scheme}://#{@host}:#{@port}/#{@version}"
|
58
58
|
|
@@ -72,15 +72,22 @@ module SimpleWorker
|
|
72
72
|
end
|
73
73
|
|
74
74
|
def url(command_path)
|
75
|
+
# @logger.debug "url: " + url.to_s
|
76
|
+
"/#{command_path}"
|
77
|
+
end
|
78
|
+
|
79
|
+
# Used for RestClient ones that haven't been converted to patron yet
|
80
|
+
def url_full(command_path)
|
75
81
|
url = "#{base_url}/#{command_path}"
|
76
82
|
# @logger.debug "url: " + url.to_s
|
77
83
|
url
|
78
84
|
end
|
79
85
|
|
80
86
|
def process_ex(ex)
|
87
|
+
logger.error "EX #{ex.class.name}: #{ex.message}"
|
81
88
|
body = ex.http_body
|
82
|
-
|
83
|
-
|
89
|
+
logger.debug 'EX http_code: ' + ex.http_code.to_s
|
90
|
+
logger.debug 'EX BODY=' + body.to_s
|
84
91
|
decoded_ex = JSON.parse(body)
|
85
92
|
exception = Exception.new(ex.message + ": " + decoded_ex["msg"])
|
86
93
|
exception.set_backtrace(decoded_ex["backtrace"].split(",")) if decoded_ex["backtrace"]
|
@@ -106,7 +113,7 @@ module SimpleWorker
|
|
106
113
|
full_url = url(method)
|
107
114
|
all_params = add_params(method, params)
|
108
115
|
url_plus_params = append_params(full_url, all_params)
|
109
|
-
|
116
|
+
logger.debug 'get url=' + url_plus_params
|
110
117
|
response = @http_sess.request(:get, url_plus_params,
|
111
118
|
{},
|
112
119
|
{})
|
@@ -119,39 +126,39 @@ module SimpleWorker
|
|
119
126
|
def post_file(method, file, params={}, options={})
|
120
127
|
begin
|
121
128
|
data = add_params(method, params).to_json
|
122
|
-
url =
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
129
|
+
url = url_full(method)
|
130
|
+
logger.debug "post_file url = " + url
|
131
|
+
logger.debug "data = " + data
|
132
|
+
logger.debug "params = " + params.inspect
|
133
|
+
logger.debug "options = " + options.inspect
|
127
134
|
# todo: replace with patron
|
128
|
-
parse_response(RestClient.post(append_params(url
|
129
|
-
rescue Exception => ex
|
135
|
+
parse_response(RestClient.post(append_params(url, add_params(method, params)), {:data => data, :file => file}, :content_type => 'application/json'), options)
|
136
|
+
rescue RestClient::Exception => ex
|
130
137
|
process_ex(ex)
|
131
138
|
end
|
132
139
|
end
|
133
140
|
|
134
141
|
def post(method, params={}, options={})
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
142
|
+
logger.debug "params = " + params.inspect
|
143
|
+
logger.debug "options = " + options.inspect
|
144
|
+
logger.debug "params.payload = " + params[:payload].inspect
|
145
|
+
logger.debug "token = "+ token.inspect
|
139
146
|
begin
|
140
147
|
url = url(method) + "?oauth=" + token
|
141
|
-
|
148
|
+
logger.debug 'post url=' + url
|
142
149
|
json = add_params(method, params).to_json
|
143
|
-
|
150
|
+
logger.debug 'body=' + json
|
144
151
|
response = @http_sess.post(url, json, {"Content-Type" => 'application/json'})
|
145
152
|
check_response(response)
|
146
|
-
|
153
|
+
logger.debug 'response: ' + response.inspect
|
147
154
|
body = response.body
|
148
155
|
parse_response(body, options)
|
149
156
|
rescue SimpleWorker::RequestError => ex
|
150
157
|
# let it throw, came from check_response
|
151
158
|
raise ex
|
152
159
|
rescue Exception => ex
|
153
|
-
|
154
|
-
|
160
|
+
logger.warn("Exception in post! #{ex.message}")
|
161
|
+
logger.warn(ex.backtrace.join("\n"))
|
155
162
|
process_ex(ex)
|
156
163
|
end
|
157
164
|
end
|
@@ -160,7 +167,7 @@ module SimpleWorker
|
|
160
167
|
def put(method, body, options={})
|
161
168
|
begin
|
162
169
|
# todo: replace with patron
|
163
|
-
parse_response RestClient.put(
|
170
|
+
parse_response RestClient.put(url_full(method), add_params(method, body).to_json, headers), options
|
164
171
|
rescue RestClient::Exception => ex
|
165
172
|
process_ex(ex)
|
166
173
|
end
|
@@ -169,7 +176,7 @@ module SimpleWorker
|
|
169
176
|
def delete(method, params={}, options={})
|
170
177
|
begin
|
171
178
|
# todo: replace with patron
|
172
|
-
parse_response RestClient.delete(append_params(
|
179
|
+
parse_response RestClient.delete(append_params(url_full(method), add_params(method, params))), options
|
173
180
|
rescue RestClient::Exception => ex
|
174
181
|
process_ex(ex)
|
175
182
|
end
|
data/lib/simple_worker/base.rb
CHANGED
@@ -6,6 +6,7 @@ module SimpleWorker
|
|
6
6
|
class Base
|
7
7
|
|
8
8
|
attr_accessor :task_set_id, :task_id, :schedule_id
|
9
|
+
attr_reader :response
|
9
10
|
|
10
11
|
class << self
|
11
12
|
attr_accessor :subclass, :caller_file
|
@@ -218,6 +219,7 @@ module SimpleWorker
|
|
218
219
|
|
219
220
|
response = SimpleWorker.service.queue(self.class.name, sw_get_data, options)
|
220
221
|
SimpleWorker.service.logger.debug 'queue response=' + response.inspect
|
222
|
+
@response = response
|
221
223
|
@task_id = response["tasks"][0]["id"]
|
222
224
|
response
|
223
225
|
end
|
data/lib/simple_worker/config.rb
CHANGED
@@ -12,7 +12,7 @@ module SimpleWorker
|
|
12
12
|
class Config
|
13
13
|
attr_accessor :token,
|
14
14
|
:project_id,
|
15
|
-
|
15
|
+
:scheme,
|
16
16
|
:host,
|
17
17
|
:port,
|
18
18
|
:global_attributes,
|
@@ -28,7 +28,7 @@ module SimpleWorker
|
|
28
28
|
:unmerged,
|
29
29
|
:merged_gems,
|
30
30
|
:unmerged_gems,
|
31
|
-
|
31
|
+
:force_upload
|
32
32
|
|
33
33
|
|
34
34
|
def initialize
|
@@ -134,7 +134,7 @@ module SimpleWorker
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
else
|
137
|
-
|
137
|
+
SimpleWorker.logger.warn "Could not find '#{gem_info[:name]}' specified in Bundler, continuing anyways."
|
138
138
|
end
|
139
139
|
# else
|
140
140
|
# SimpleWorker.logger.warn "Could not find gem spec for #{gem_info[:name]}"
|
@@ -126,7 +126,6 @@ module SimpleWorker
|
|
126
126
|
tmp_file = File.join(Dir.tmpdir(), 'runner.rb')
|
127
127
|
File.open(tmp_file, "w") do |f|
|
128
128
|
|
129
|
-
f.write("begin\n") #error handling block start
|
130
129
|
f.write("
|
131
130
|
# Find environment (-e)
|
132
131
|
dirname = ''
|
@@ -154,10 +153,7 @@ require 'json'
|
|
154
153
|
# require merged gems
|
155
154
|
merged_gems.each_pair do |k, gem|
|
156
155
|
SimpleWorker.logger.debug "Bundling gem #{gem[:name]}..."
|
157
|
-
|
158
|
-
f.write "$LOAD_PATH << File.join(File.dirname(__FILE__), '/gems/#{gem[:name]}/lib')\n"
|
159
|
-
end
|
160
|
-
# unless gem[:no_require]
|
156
|
+
f.write "$LOAD_PATH << File.join(File.dirname(__FILE__), '/gems/#{gem[:name]}/lib')\n"
|
161
157
|
SimpleWorker.logger.debug 'writing requires: ' + gem[:require].inspect
|
162
158
|
if gem[:require].nil?
|
163
159
|
gem[:require] = []
|
@@ -246,13 +242,6 @@ end
|
|
246
242
|
runner_return_data = runner.run
|
247
243
|
")
|
248
244
|
|
249
|
-
#error handling block - end
|
250
|
-
f.write("\nrescue Exception => ex
|
251
|
-
$stderr.puts '_error_from_sw_'
|
252
|
-
raise ex
|
253
|
-
end
|
254
|
-
")
|
255
|
-
|
256
245
|
end
|
257
246
|
#puts 'funner.rb=' + tmp_file
|
258
247
|
merge['runner.rb'] = {:path=>tmp_file}
|
@@ -396,8 +385,8 @@ end
|
|
396
385
|
end
|
397
386
|
|
398
387
|
def check_config
|
399
|
-
if self.config.nil? || self.config.token.nil?
|
400
|
-
raise "Invalid SimpleWorker configuration,
|
388
|
+
if self.config.nil? || self.config.token.nil? || self.config.project_id.nil?
|
389
|
+
raise "Invalid SimpleWorker configuration, token and project_id required."
|
401
390
|
end
|
402
391
|
end
|
403
392
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: simple_worker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease: 6
|
5
|
-
version: 2.0.0.beta.
|
5
|
+
version: 2.0.0.beta.16
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Travis Reeder
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-11-02 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: zip
|