simple_worker 0.5.5 → 0.5.6
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 +14 -0
- data/lib/simple_worker/base.rb +22 -1
- data/lib/simple_worker/service.rb +28 -26
- data/test/awesome_job.rb +1 -1
- data/test/test_inheritance.rb +1 -1
- metadata +3 -3
data/README.markdown
CHANGED
@@ -123,6 +123,10 @@ The log will be available for viewing via the SimpleWorker UI or via log in the
|
|
123
123
|
|
124
124
|
SimpleWorker.service.log(job_id)
|
125
125
|
|
126
|
+
or if you still have a handle to your worker object:
|
127
|
+
|
128
|
+
worker.get_log
|
129
|
+
|
126
130
|
Setting Progress
|
127
131
|
----------------
|
128
132
|
|
@@ -218,6 +222,16 @@ uploaded separately and treated as distinctly separate workers.
|
|
218
222
|
|
219
223
|
merge_worker "./other_worker.rb", "OtherWorker"
|
220
224
|
|
225
|
+
Merging Gems
|
226
|
+
---------------------
|
227
|
+
|
228
|
+
This allows you to use any gem you'd like with SimpleWorker.
|
229
|
+
|
230
|
+
merge_gem "some_gem"
|
231
|
+
merge_gem "some_gem_with_version", "1.2.3"
|
232
|
+
|
233
|
+
[Check here for more info on merge_gem](http://support.simpleworker.com/kb/working-with-simpleworker/merging-gems-into-your-worker).
|
234
|
+
|
221
235
|
|
222
236
|
Configuration Options
|
223
237
|
---------------------
|
data/lib/simple_worker/base.rb
CHANGED
@@ -31,7 +31,7 @@ module SimpleWorker
|
|
31
31
|
# caller_file = splits[0] + ":" + splits[1]
|
32
32
|
caller_file = caller[0][0...(caller[0].index(":in"))]
|
33
33
|
caller_file = caller_file[0...(caller_file.rindex(":"))]
|
34
|
-
#
|
34
|
+
# puts 'caller_file=' + caller_file
|
35
35
|
# don't need these class_variables anymore probably
|
36
36
|
subclass.instance_variable_set(:@caller_file, caller_file)
|
37
37
|
|
@@ -189,6 +189,25 @@ module SimpleWorker
|
|
189
189
|
SimpleWorker.service.status(task_id)
|
190
190
|
end
|
191
191
|
|
192
|
+
# will return after job has completed or errored out.
|
193
|
+
# Returns status.
|
194
|
+
# todo: add a :timeout option
|
195
|
+
def wait_until_complete
|
196
|
+
tries = 0
|
197
|
+
status = nil
|
198
|
+
sleep 1
|
199
|
+
while tries < 100
|
200
|
+
status = self.status
|
201
|
+
puts "Waiting... status=" + status["status"]
|
202
|
+
if status["status"] != "queued" && status["status"] != "running"
|
203
|
+
break
|
204
|
+
end
|
205
|
+
sleep 2
|
206
|
+
end
|
207
|
+
status
|
208
|
+
end
|
209
|
+
|
210
|
+
|
192
211
|
def upload
|
193
212
|
upload_if_needed
|
194
213
|
end
|
@@ -217,6 +236,7 @@ module SimpleWorker
|
|
217
236
|
SimpleWorker.service.schedule_status(schedule_id)
|
218
237
|
end
|
219
238
|
|
239
|
+
# Retrieves the log for this worker from the SimpleWorker service.
|
220
240
|
def get_log
|
221
241
|
SimpleWorker.service.log(task_id)
|
222
242
|
end
|
@@ -295,6 +315,7 @@ module SimpleWorker
|
|
295
315
|
payload[iv] = instance_variable_get(iv)
|
296
316
|
end
|
297
317
|
data[:attr_encoded] = Base64.encode64(payload.to_json)
|
318
|
+
data[:file_name] = File.basename(self.class.instance_variable_get(:@caller_file))
|
298
319
|
|
299
320
|
config_data = SimpleWorker.config.get_atts_to_send
|
300
321
|
data[:sw_config] = config_data
|
@@ -4,7 +4,7 @@ require 'appoxy_api'
|
|
4
4
|
require 'zip'
|
5
5
|
module SimpleWorker
|
6
6
|
|
7
|
-
@@logger
|
7
|
+
@@logger = Logger.new(STDOUT)
|
8
8
|
@@logger.level = Logger::INFO
|
9
9
|
|
10
10
|
def self.logger
|
@@ -32,15 +32,15 @@ module SimpleWorker
|
|
32
32
|
def upload(filename, class_name, options={})
|
33
33
|
# puts "Uploading #{class_name}"
|
34
34
|
# check whether it should upload again
|
35
|
-
tmp
|
36
|
-
md5file
|
35
|
+
tmp = Dir.tmpdir()
|
36
|
+
md5file = "simple_worker_#{class_name.gsub("::", ".")}_#{access_key[0, 8]}.md5"
|
37
37
|
existing_md5 = nil
|
38
|
-
f
|
38
|
+
f = File.join(tmp, md5file)
|
39
39
|
if File.exists?(f)
|
40
40
|
existing_md5 = IO.read(f)
|
41
41
|
end
|
42
42
|
# Check for code changes.
|
43
|
-
md5
|
43
|
+
md5 = Digest::MD5.hexdigest(File.read(filename))
|
44
44
|
new_code = false
|
45
45
|
if md5 != existing_md5
|
46
46
|
SimpleWorker.logger.info "Uploading #{class_name}, code modified."
|
@@ -52,14 +52,13 @@ module SimpleWorker
|
|
52
52
|
end
|
53
53
|
|
54
54
|
|
55
|
-
|
55
|
+
zip_filename = build_merged_file(filename, options[:merge], options[:unmerge], options[:merged_gems])
|
56
56
|
|
57
57
|
# sys.classes[subclass].__file__
|
58
58
|
# puts '__FILE__=' + Base.subclass.__file__.to_s
|
59
59
|
# puts "new md5=" + md5
|
60
60
|
|
61
61
|
|
62
|
-
|
63
62
|
if new_code
|
64
63
|
# mystring = nil
|
65
64
|
# file = File.open(filename, "r") do |f|
|
@@ -67,8 +66,12 @@ module SimpleWorker
|
|
67
66
|
# end
|
68
67
|
# mystring = Base64.encode64(mystring)
|
69
68
|
# puts 'code=' + mystring
|
70
|
-
options
|
71
|
-
|
69
|
+
options = {
|
70
|
+
"class_name"=>class_name,
|
71
|
+
"file_name"=> File.basename(filename)
|
72
|
+
}
|
73
|
+
puts 'options for upload=' + options.inspect
|
74
|
+
ret = post_file("code/put", File.new(zip_filename), options)
|
72
75
|
ret
|
73
76
|
end
|
74
77
|
end
|
@@ -77,7 +80,7 @@ module SimpleWorker
|
|
77
80
|
gem_name =(full_gem_name.match(/^[a-zA-Z0-9\-_]+/)[0])
|
78
81
|
puts "Searching #{gem_name}"
|
79
82
|
searcher = Gem::GemPathSearcher.new
|
80
|
-
gems
|
83
|
+
gems = searcher.find_all(gem_name)
|
81
84
|
gems = gems.select { |g| g.version.version==version } if version
|
82
85
|
if !gems.empty?
|
83
86
|
gem = gems.first
|
@@ -149,7 +152,7 @@ module SimpleWorker
|
|
149
152
|
# todo: remove secret key?? Can use worker service from within a worker without it now
|
150
153
|
hash_to_send["sw_access_key"] = self.access_key
|
151
154
|
hash_to_send["sw_secret_key"] = self.secret_key
|
152
|
-
hash_to_send["api_version"]
|
155
|
+
hash_to_send["api_version"] = SimpleWorker.api_version
|
153
156
|
end
|
154
157
|
|
155
158
|
def check_config
|
@@ -167,8 +170,8 @@ module SimpleWorker
|
|
167
170
|
data = [data]
|
168
171
|
end
|
169
172
|
# p data
|
170
|
-
hash_to_send
|
171
|
-
hash_to_send["payload"]
|
173
|
+
hash_to_send = {}
|
174
|
+
hash_to_send["payload"] = data
|
172
175
|
hash_to_send["class_name"] = class_name
|
173
176
|
hash_to_send["priority"] = options[:priority] if options[:priority]
|
174
177
|
hash_to_send["options"] = options
|
@@ -182,15 +185,14 @@ module SimpleWorker
|
|
182
185
|
end
|
183
186
|
|
184
187
|
def queue_raw(class_name, data={})
|
185
|
-
params
|
186
|
-
hash_to_send
|
188
|
+
params = nil
|
189
|
+
hash_to_send = data
|
187
190
|
hash_to_send["class_name"] = class_name
|
188
|
-
ret
|
191
|
+
ret = post("queue/add", hash_to_send)
|
189
192
|
ret
|
190
193
|
|
191
194
|
end
|
192
195
|
|
193
|
-
|
194
196
|
#
|
195
197
|
# schedule: hash of scheduling options that can include:
|
196
198
|
# Required:
|
@@ -207,10 +209,10 @@ module SimpleWorker
|
|
207
209
|
# if !data.is_a?(Array)
|
208
210
|
# data = [data]
|
209
211
|
# end
|
210
|
-
hash_to_send
|
211
|
-
hash_to_send["payload"]
|
212
|
+
hash_to_send = {}
|
213
|
+
hash_to_send["payload"] = data
|
212
214
|
hash_to_send["class_name"] = class_name
|
213
|
-
hash_to_send["schedule"]
|
215
|
+
hash_to_send["schedule"] = schedule
|
214
216
|
add_sw_params(hash_to_send)
|
215
217
|
# puts ' about to send ' + hash_to_send.inspect
|
216
218
|
ret = post("scheduler/schedule", hash_to_send)
|
@@ -219,33 +221,33 @@ module SimpleWorker
|
|
219
221
|
|
220
222
|
def cancel_schedule(scheduled_task_id)
|
221
223
|
raise "Must include a schedule id." if scheduled_task_id.blank?
|
222
|
-
hash_to_send
|
224
|
+
hash_to_send = {}
|
223
225
|
hash_to_send["scheduled_task_id"] = scheduled_task_id
|
224
|
-
ret
|
226
|
+
ret = post("scheduler/cancel", hash_to_send)
|
225
227
|
ret
|
226
228
|
end
|
227
229
|
|
228
230
|
def get_schedules()
|
229
231
|
hash_to_send = {}
|
230
|
-
ret
|
232
|
+
ret = get("scheduler/list", hash_to_send)
|
231
233
|
ret
|
232
234
|
end
|
233
235
|
|
234
236
|
def status(task_id)
|
235
237
|
data = {"task_id"=>task_id}
|
236
|
-
ret
|
238
|
+
ret = get("task/status", data)
|
237
239
|
ret
|
238
240
|
end
|
239
241
|
|
240
242
|
def schedule_status(schedule_id)
|
241
243
|
data = {"schedule_id"=>schedule_id}
|
242
|
-
ret
|
244
|
+
ret = get("scheduler/status", data)
|
243
245
|
ret
|
244
246
|
end
|
245
247
|
|
246
248
|
def log(task_id)
|
247
249
|
data = {"task_id"=>task_id}
|
248
|
-
ret
|
250
|
+
ret = get("task/log", data, {:parse=>false})
|
249
251
|
# puts ' ret=' + ret.inspect
|
250
252
|
# ret["log"] = Base64.decode64(ret["log"])
|
251
253
|
ret
|
data/test/awesome_job.rb
CHANGED
data/test/test_inheritance.rb
CHANGED
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 5
|
8
|
-
-
|
9
|
-
version: 0.5.
|
8
|
+
- 6
|
9
|
+
version: 0.5.6
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Travis Reeder
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-30 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|