simple_worker 0.3.6 → 0.3.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_worker/base.rb +22 -14
- data/lib/simple_worker/used_in_worker.rb +1 -1
- data/lib/simple_worker.rb +3 -0
- data/test/models/model_1.rb +4 -3
- data/test/scheduled_worker.rb +6 -1
- data/test/second_worker.rb +8 -0
- data/test/test_simple_worker.rb +63 -59
- data/test/test_worker.rb +2 -1
- data/test/test_worker_2.rb +4 -3
- metadata +3 -3
data/lib/simple_worker/base.rb
CHANGED
@@ -11,9 +11,11 @@ module SimpleWorker
|
|
11
11
|
class << self
|
12
12
|
attr_accessor :subclass, :caller_file
|
13
13
|
@merged = []
|
14
|
+
@merged_workers = []
|
14
15
|
|
15
16
|
def reset!
|
16
17
|
@merged = []
|
18
|
+
@merged_workers = []
|
17
19
|
end
|
18
20
|
|
19
21
|
def inherited(subclass)
|
@@ -43,6 +45,13 @@ module SimpleWorker
|
|
43
45
|
@merged << File.expand_path(f)
|
44
46
|
end
|
45
47
|
end
|
48
|
+
|
49
|
+
def merge_worker(file, class_name)
|
50
|
+
puts 'merge_worker in ' + self.name
|
51
|
+
puts 'FUCK'
|
52
|
+
merge(file)
|
53
|
+
@merged_workers << [File.expand_path(file), class_name]
|
54
|
+
end
|
46
55
|
end
|
47
56
|
|
48
57
|
|
@@ -65,6 +74,7 @@ module SimpleWorker
|
|
65
74
|
|
66
75
|
# Will send in all instance_variables.
|
67
76
|
def queue
|
77
|
+
puts 'in queue'
|
68
78
|
upload_if_needed
|
69
79
|
|
70
80
|
response = SimpleWorker.service.queue(self.class.name, sw_get_data)
|
@@ -78,6 +88,9 @@ module SimpleWorker
|
|
78
88
|
SimpleWorker.service.status(task_id)
|
79
89
|
end
|
80
90
|
|
91
|
+
def upload
|
92
|
+
upload_if_needed
|
93
|
+
end
|
81
94
|
|
82
95
|
def schedule(schedule)
|
83
96
|
upload_if_needed
|
@@ -92,23 +105,11 @@ module SimpleWorker
|
|
92
105
|
SimpleWorker.service.schedule_status(schedule_id)
|
93
106
|
end
|
94
107
|
|
95
|
-
|
96
|
-
# def queue_other(class_name, data)
|
97
|
-
# SimpleWorker.service.queue(class_name, data)
|
98
|
-
# end
|
99
|
-
#
|
100
|
-
# def schedule_other(class_name, data, schedule)
|
101
|
-
# SimpleWorker.service.schedule(class_name, data, schedule)
|
102
|
-
# end
|
103
|
-
|
104
108
|
private
|
105
|
-
|
109
|
+
|
106
110
|
def upload_if_needed
|
107
111
|
|
108
|
-
|
109
|
-
# puts "#{ sprintf("%2s", idx) } #{feature}"
|
110
|
-
# if feature[feature.rindex("/")..feature.length] ==
|
111
|
-
#}
|
112
|
+
puts 'upload_if_needed'
|
112
113
|
unless uploaded?
|
113
114
|
subclass = self.class
|
114
115
|
rfile = subclass.instance_variable_get(:@caller_file) # Base.caller_file # File.expand_path(Base.subclass)
|
@@ -119,6 +120,13 @@ module SimpleWorker
|
|
119
120
|
else
|
120
121
|
puts 'already uploaded for ' + self.class.name
|
121
122
|
end
|
123
|
+
puts 'uploading merged workers'
|
124
|
+
self.class.instance_variable_get(:@merged_workers).each do |mw|
|
125
|
+
# to support merges in the secondary worker, we should instantiate it here, then call "upload"
|
126
|
+
puts 'instantiating and uploading ' + mw[1]
|
127
|
+
Kernel.const_get(mw[1]).new.upload
|
128
|
+
# SimpleWorker.service.upload(mw[0], mw[1])
|
129
|
+
end
|
122
130
|
end
|
123
131
|
|
124
132
|
def sw_get_data
|
data/lib/simple_worker.rb
CHANGED
@@ -1,8 +1,11 @@
|
|
1
|
+
puts 'REQUIRING THIS SHIT!'
|
2
|
+
|
1
3
|
require 'appoxy_api'
|
2
4
|
require File.join(File.dirname(__FILE__), 'simple_worker', 'base')
|
3
5
|
require File.join(File.dirname(__FILE__), 'simple_worker', 'config')
|
4
6
|
require File.join(File.dirname(__FILE__), 'simple_worker', 'used_in_worker')
|
5
7
|
|
8
|
+
|
6
9
|
module SimpleWorker
|
7
10
|
|
8
11
|
class << self
|
data/test/models/model_1.rb
CHANGED
@@ -1,7 +1,8 @@
|
|
1
1
|
begin
|
2
|
-
require File.join(File.dirname(__FILE__), '
|
3
|
-
rescue Exception
|
4
|
-
|
2
|
+
require File.join(File.dirname(__FILE__), '../../lib/simple_worker')
|
3
|
+
rescue Exception => ex
|
4
|
+
puts 'ERROR!!! ' + ex.message
|
5
|
+
# require 'simple_worker'
|
5
6
|
end
|
6
7
|
|
7
8
|
|
data/test/scheduled_worker.rb
CHANGED
data/test/second_worker.rb
CHANGED
@@ -1,6 +1,14 @@
|
|
1
|
+
begin
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/simple_worker')
|
3
|
+
rescue Exception => ex
|
4
|
+
puts ex.message
|
5
|
+
require 'simple_worker'
|
6
|
+
end
|
7
|
+
|
1
8
|
class SecondWorker < SimpleWorker::Base
|
2
9
|
attr_accessor :start_time, :num
|
3
10
|
|
11
|
+
# change
|
4
12
|
|
5
13
|
def run
|
6
14
|
log self.to_s
|
data/test/test_simple_worker.rb
CHANGED
@@ -2,7 +2,8 @@ require 'test/unit'
|
|
2
2
|
require 'yaml'
|
3
3
|
begin
|
4
4
|
require File.join(File.dirname(__FILE__), '../lib/simple_worker')
|
5
|
-
rescue
|
5
|
+
rescue Exception => ex
|
6
|
+
puts ex.message
|
6
7
|
require 'simple_worker'
|
7
8
|
end
|
8
9
|
require File.join(File.dirname(__FILE__), "./test_worker")
|
@@ -48,7 +49,10 @@ class SimpleWorkerTests < Test::Unit::TestCase
|
|
48
49
|
# end
|
49
50
|
|
50
51
|
# queue up a task
|
52
|
+
puts 'queuing ' + tw.inspect
|
51
53
|
response_hash_single = tw.queue
|
54
|
+
|
55
|
+
|
52
56
|
puts 'response_hash=' + response_hash_single.inspect
|
53
57
|
puts 'task_set_id=' + tw.task_set_id
|
54
58
|
puts 'task_id=' + tw.task_id
|
@@ -61,64 +65,64 @@ class SimpleWorkerTests < Test::Unit::TestCase
|
|
61
65
|
assert tw.status["status"] == "complete"
|
62
66
|
|
63
67
|
end
|
64
|
-
|
65
|
-
|
66
|
-
def test_queue
|
67
|
-
|
68
|
-
|
69
|
-
# Upload latest runner code
|
70
|
-
@worker.upload(File.join(File.dirname(__FILE__), "./test_worker.rb"), "TestWorker")
|
71
|
-
|
72
|
-
# Add something to queue, get task ID back
|
73
|
-
# Single task
|
74
|
-
response_hash_single = @worker.queue("TestWorker", {"s3_key"=>"single runner", "times"=>10})
|
75
|
-
|
76
|
-
# task set
|
77
|
-
response_hash = @worker.queue("TestWorker", [{"id"=>"local_id", "s3_key"=>"some key", "times"=>4}, {"s3_key"=>"some key2", "times"=>3}, {"s3_key"=>"some key", "times"=>2}])
|
78
|
-
|
79
|
-
# Check status
|
80
|
-
tasks = response_hash["tasks"]
|
81
|
-
puts 'tasks.size=' + tasks.size.to_s
|
82
|
-
while tasks.size > 0
|
83
|
-
tasks.each do |t|
|
84
|
-
puts "t=" + t.inspect
|
85
|
-
status_response = @worker.status(t["task_id"])
|
86
|
-
puts 'status for ' + t["task_id"] + ' = ' + status_response["status"]
|
87
|
-
if status_response["status"] == "complete" || status_response["status"] == "error" || status_response["status"] == "cancelled"
|
88
|
-
tasks.delete(t)
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
# lets try to get the log now too
|
94
|
-
task_id = response_hash_single["tasks"][0]["task_id"]
|
95
|
-
puts 'task_id=' + task_id
|
96
|
-
status_with_log = @worker.log(task_id)
|
97
|
-
puts 'log=' + status_with_log.inspect
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
def test_scheduled
|
102
|
-
|
103
|
-
# Upload latest runner code
|
104
|
-
@worker.upload(File.join(File.dirname(__FILE__), "./scheduled_worker.rb"), "ScheduledWorker")
|
105
|
-
|
106
|
-
start_at = 10.seconds.since
|
107
|
-
#start_at = start_at.gmtime # testing different timezone
|
108
|
-
puts 'start_at =' + start_at.inspect
|
109
|
-
response_hash = @worker.schedule("ScheduledWorker", {"msg"=>"One time test."}, {:start_at=>start_at})
|
110
|
-
puts 'response_hash=' + response_hash.inspect
|
111
|
-
|
112
|
-
start_at = 10.seconds.since
|
113
|
-
response_hash = @worker.schedule("ScheduledWorker", {"msg"=>"Run times test"}, {:start_at=>start_at, :run_every=>30, :run_times=>3})
|
114
|
-
puts 'response_hash=' + response_hash.inspect
|
115
|
-
|
116
|
-
start_at = 10.seconds.since
|
117
|
-
end_at = 2.minutes.since
|
118
|
-
response_hash = @worker.schedule("ScheduledWorker", {"msg"=>"End at test"}, {:start_at=>start_at, :run_every=>30, :end_at=>end_at, :run_times=>20})
|
119
|
-
puts 'response_hash=' + response_hash.inspect
|
120
|
-
|
121
|
-
end
|
68
|
+
#
|
69
|
+
#
|
70
|
+
# def test_queue
|
71
|
+
#
|
72
|
+
#
|
73
|
+
# # Upload latest runner code
|
74
|
+
# @worker.upload(File.join(File.dirname(__FILE__), "./test_worker.rb"), "TestWorker")
|
75
|
+
#
|
76
|
+
# # Add something to queue, get task ID back
|
77
|
+
# # Single task
|
78
|
+
# response_hash_single = @worker.queue("TestWorker", {"s3_key"=>"single runner", "times"=>10})
|
79
|
+
#
|
80
|
+
# # task set
|
81
|
+
# response_hash = @worker.queue("TestWorker", [{"id"=>"local_id", "s3_key"=>"some key", "times"=>4}, {"s3_key"=>"some key2", "times"=>3}, {"s3_key"=>"some key", "times"=>2}])
|
82
|
+
#
|
83
|
+
# # Check status
|
84
|
+
# tasks = response_hash["tasks"]
|
85
|
+
# puts 'tasks.size=' + tasks.size.to_s
|
86
|
+
# while tasks.size > 0
|
87
|
+
# tasks.each do |t|
|
88
|
+
# puts "t=" + t.inspect
|
89
|
+
# status_response = @worker.status(t["task_id"])
|
90
|
+
# puts 'status for ' + t["task_id"] + ' = ' + status_response["status"]
|
91
|
+
# if status_response["status"] == "complete" || status_response["status"] == "error" || status_response["status"] == "cancelled"
|
92
|
+
# tasks.delete(t)
|
93
|
+
# end
|
94
|
+
# end
|
95
|
+
# end
|
96
|
+
#
|
97
|
+
# # lets try to get the log now too
|
98
|
+
# task_id = response_hash_single["tasks"][0]["task_id"]
|
99
|
+
# puts 'task_id=' + task_id
|
100
|
+
# status_with_log = @worker.log(task_id)
|
101
|
+
# puts 'log=' + status_with_log.inspect
|
102
|
+
#
|
103
|
+
# end
|
104
|
+
#
|
105
|
+
# def test_scheduled
|
106
|
+
#
|
107
|
+
# # Upload latest runner code
|
108
|
+
# @worker.upload(File.join(File.dirname(__FILE__), "./scheduled_worker.rb"), "ScheduledWorker")
|
109
|
+
#
|
110
|
+
# start_at = 10.seconds.since
|
111
|
+
# #start_at = start_at.gmtime # testing different timezone
|
112
|
+
# puts 'start_at =' + start_at.inspect
|
113
|
+
# response_hash = @worker.schedule("ScheduledWorker", {"msg"=>"One time test."}, {:start_at=>start_at})
|
114
|
+
# puts 'response_hash=' + response_hash.inspect
|
115
|
+
#
|
116
|
+
# start_at = 10.seconds.since
|
117
|
+
# response_hash = @worker.schedule("ScheduledWorker", {"msg"=>"Run times test"}, {:start_at=>start_at, :run_every=>30, :run_times=>3})
|
118
|
+
# puts 'response_hash=' + response_hash.inspect
|
119
|
+
#
|
120
|
+
# start_at = 10.seconds.since
|
121
|
+
# end_at = 2.minutes.since
|
122
|
+
# response_hash = @worker.schedule("ScheduledWorker", {"msg"=>"End at test"}, {:start_at=>start_at, :run_every=>30, :end_at=>end_at, :run_times=>20})
|
123
|
+
# puts 'response_hash=' + response_hash.inspect
|
124
|
+
#
|
125
|
+
# end
|
122
126
|
|
123
127
|
end
|
124
128
|
|
data/test/test_worker.rb
CHANGED
data/test/test_worker_2.rb
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
begin
|
2
2
|
require File.join(File.dirname(__FILE__), '../lib/simple_worker')
|
3
|
-
rescue Exception
|
3
|
+
rescue Exception => ex
|
4
|
+
puts ex.message
|
4
5
|
require 'simple_worker'
|
5
6
|
end
|
6
7
|
|
7
|
-
# Bump for new checksum.
|
8
|
+
# Bump for new checksum.sdf
|
8
9
|
class TestWorker2 < SimpleWorker::Base
|
9
10
|
|
10
11
|
merge 'models/model_1.rb'
|
11
|
-
|
12
|
+
merge_worker 'second_worker.rb', 'SecondWorker'
|
12
13
|
|
13
14
|
attr_accessor :s3_key, :times, :x
|
14
15
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_worker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 3
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 8
|
10
|
+
version: 0.3.8
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Reeder
|