simple_worker 0.3.3 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_worker/base.rb +5 -5
- data/lib/simple_worker.rb +6 -6
- data/test/second_worker.rb +12 -0
- data/test/test_simple_worker.rb +7 -7
- data/test/test_worker_2.rb +21 -4
- metadata +6 -4
data/lib/simple_worker/base.rb
CHANGED
@@ -19,13 +19,13 @@ module SimpleWorker
|
|
19
19
|
def inherited(subclass)
|
20
20
|
subclass.reset!
|
21
21
|
|
22
|
-
puts "New subclass: #{subclass}"
|
23
|
-
puts "subclass.inspect=" + subclass.inspect
|
24
|
-
puts 'existing caller=' + (subclass.instance_variable_defined?(:@caller_file) ? subclass.instance_variable_get(:@caller_file).inspect : "nil")
|
25
|
-
puts "caller=" + caller.inspect
|
22
|
+
# puts "New subclass: #{subclass}"
|
23
|
+
# puts "subclass.inspect=" + subclass.inspect
|
24
|
+
# puts 'existing caller=' + (subclass.instance_variable_defined?(:@caller_file) ? subclass.instance_variable_get(:@caller_file).inspect : "nil")
|
25
|
+
# puts "caller=" + caller.inspect
|
26
26
|
splits = caller[0].split(":")
|
27
27
|
caller_file = splits[0] + ":" + splits[1]
|
28
|
-
puts 'caller_file=' + caller_file
|
28
|
+
# puts 'caller_file=' + caller_file
|
29
29
|
# don't need these class_variables anymore probably
|
30
30
|
subclass.instance_variable_set(:@caller_file, caller_file)
|
31
31
|
|
data/lib/simple_worker.rb
CHANGED
@@ -9,12 +9,11 @@ module SimpleWorker
|
|
9
9
|
attr_accessor :config,
|
10
10
|
:service
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
SimpleWorker.service = Service.new(config.access_key, config.secret_key, :config=>config)
|
12
|
+
def configure()
|
13
|
+
SimpleWorker.config ||= Config.new
|
14
|
+
yield(config)
|
15
|
+
SimpleWorker.service = Service.new(config.access_key, config.secret_key, :config=>config)
|
16
|
+
end
|
18
17
|
end
|
19
18
|
|
20
19
|
class Service < Appoxy::Api::Client
|
@@ -81,6 +80,7 @@ module SimpleWorker
|
|
81
80
|
end
|
82
81
|
|
83
82
|
def add_sw_params(hash_to_send)
|
83
|
+
# todo: remove secret key?? Can use worker service from within a worker without it now
|
84
84
|
hash_to_send["sw_access_key"] = self.access_key
|
85
85
|
hash_to_send["sw_secret_key"] = self.secret_key
|
86
86
|
end
|
data/test/test_simple_worker.rb
CHANGED
@@ -39,13 +39,13 @@ class SimpleWorkerTests < Test::Unit::TestCase
|
|
39
39
|
tw.x = true
|
40
40
|
|
41
41
|
# schedule up a task
|
42
|
-
start_at = 10.seconds.since
|
43
|
-
response_hash_single = tw.schedule(:start_at=>start_at, :run_every=>30, :run_times=>3)
|
44
|
-
puts 'response_hash=' + response_hash_single.inspect
|
45
|
-
|
46
|
-
10.times do |i|
|
47
|
-
puts "status #{i}: " + tw.schedule_status.inspect
|
48
|
-
end
|
42
|
+
# start_at = 10.seconds.since
|
43
|
+
# response_hash_single = tw.schedule(:start_at=>start_at, :run_every=>30, :run_times=>3)
|
44
|
+
# puts 'response_hash=' + response_hash_single.inspect
|
45
|
+
#
|
46
|
+
# 10.times do |i|
|
47
|
+
# puts "status #{i}: " + tw.schedule_status.inspect
|
48
|
+
# end
|
49
49
|
|
50
50
|
# queue up a task
|
51
51
|
response_hash_single = tw.queue
|
data/test/test_worker_2.rb
CHANGED
@@ -7,7 +7,8 @@ end
|
|
7
7
|
# Bump for new checksum.
|
8
8
|
class TestWorker2 < SimpleWorker::Base
|
9
9
|
|
10
|
-
merge
|
10
|
+
merge 'models/model_1.rb'
|
11
|
+
merge 'second_worker.rb'
|
11
12
|
|
12
13
|
attr_accessor :s3_key, :times, :x
|
13
14
|
|
@@ -16,8 +17,8 @@ class TestWorker2 < SimpleWorker::Base
|
|
16
17
|
return self.class.name
|
17
18
|
end
|
18
19
|
|
19
|
-
def run
|
20
|
-
log 'running the runner for leroy '.upcase + ' with data: '
|
20
|
+
def run
|
21
|
+
log 'running the runner for leroy '.upcase + ' with data: '
|
21
22
|
|
22
23
|
log 's3_key instance_variable = ' + self.s3_key
|
23
24
|
times.times do |i|
|
@@ -28,6 +29,23 @@ class TestWorker2 < SimpleWorker::Base
|
|
28
29
|
m1 = Model1.new
|
29
30
|
log "I made a new model1"
|
30
31
|
m1.say_hello
|
32
|
+
|
33
|
+
second_workers = []
|
34
|
+
now = Time.now
|
35
|
+
10.times do |i|
|
36
|
+
second_worker = SecondWorker.new
|
37
|
+
second_worker.start_time = now
|
38
|
+
second_worker.num = i
|
39
|
+
second_worker.queue
|
40
|
+
second_workers << second_worker
|
41
|
+
end
|
42
|
+
|
43
|
+
10.times do |i|
|
44
|
+
second_workers.each do |sw|
|
45
|
+
puts sw.to_s
|
46
|
+
puts sw.status["status"].to_s
|
47
|
+
end
|
48
|
+
end
|
31
49
|
end
|
32
50
|
|
33
51
|
def set_complete(params=nil)
|
@@ -35,4 +53,3 @@ class TestWorker2 < SimpleWorker::Base
|
|
35
53
|
end
|
36
54
|
|
37
55
|
end
|
38
|
-
|
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: 25
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 3
|
9
|
-
-
|
10
|
-
version: 0.3.
|
9
|
+
- 5
|
10
|
+
version: 0.3.5
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Travis Reeder
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-26 00:00:00 -07:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -48,6 +48,7 @@ files:
|
|
48
48
|
- README.markdown
|
49
49
|
- test/models/model_1.rb
|
50
50
|
- test/scheduled_worker.rb
|
51
|
+
- test/second_worker.rb
|
51
52
|
- test/test_inheritance.rb
|
52
53
|
- test/test_simple_worker.rb
|
53
54
|
- test/test_worker.rb
|
@@ -89,6 +90,7 @@ summary: Classified
|
|
89
90
|
test_files:
|
90
91
|
- test/models/model_1.rb
|
91
92
|
- test/scheduled_worker.rb
|
93
|
+
- test/second_worker.rb
|
92
94
|
- test/test_inheritance.rb
|
93
95
|
- test/test_simple_worker.rb
|
94
96
|
- test/test_worker.rb
|