simple_worker 0.3.0 → 0.3.3
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/simple_worker/base.rb +35 -15
- data/lib/simple_worker/used_in_worker.rb +9 -0
- data/lib/simple_worker.rb +19 -0
- data/test/models/model_1.rb +21 -0
- data/test/test_worker.rb +1 -1
- data/test/test_worker_2.rb +6 -0
- metadata +19 -4
data/lib/simple_worker/base.rb
CHANGED
@@ -10,19 +10,38 @@ module SimpleWorker
|
|
10
10
|
|
11
11
|
class << self
|
12
12
|
attr_accessor :subclass, :caller_file
|
13
|
-
|
13
|
+
@merged = []
|
14
|
+
|
15
|
+
def reset!
|
16
|
+
@merged = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def inherited(subclass)
|
20
|
+
subclass.reset!
|
14
21
|
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
subclass.class_variable_set(:@@caller_file, caller_file)
|
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
|
+
splits = caller[0].split(":")
|
27
|
+
caller_file = splits[0] + ":" + splits[1]
|
28
|
+
puts 'caller_file=' + caller_file
|
29
|
+
# don't need these class_variables anymore probably
|
30
|
+
subclass.instance_variable_set(:@caller_file, caller_file)
|
25
31
|
|
32
|
+
super
|
33
|
+
end
|
34
|
+
|
35
|
+
# merges the specified files.
|
36
|
+
def merge(*files)
|
37
|
+
files.each do |f|
|
38
|
+
unless File.exist? f
|
39
|
+
raise "File not found: " + f
|
40
|
+
end
|
41
|
+
require f
|
42
|
+
@merged << File.expand_path(f)
|
43
|
+
end
|
44
|
+
end
|
26
45
|
end
|
27
46
|
|
28
47
|
|
@@ -39,7 +58,7 @@ module SimpleWorker
|
|
39
58
|
end
|
40
59
|
|
41
60
|
def uploaded?
|
42
|
-
self.class.
|
61
|
+
self.class.instance_variable_defined?(:@uploaded) && self.class.instance_variable_get(:@uploaded)
|
43
62
|
end
|
44
63
|
|
45
64
|
|
@@ -91,11 +110,11 @@ module SimpleWorker
|
|
91
110
|
#}
|
92
111
|
unless uploaded?
|
93
112
|
subclass = self.class
|
94
|
-
rfile = subclass.
|
113
|
+
rfile = subclass.instance_variable_get(:@caller_file) # Base.caller_file # File.expand_path(Base.subclass)
|
95
114
|
puts 'rfile=' + rfile.inspect
|
96
115
|
puts 'self.class.name=' + subclass.name
|
97
|
-
SimpleWorker.service.upload(rfile, subclass.name)
|
98
|
-
self.class.
|
116
|
+
SimpleWorker.service.upload(rfile, subclass.name, :merge=>self.class.instance_variable_get(:@merged))
|
117
|
+
self.class.instance_variable_set(:@uploaded, true)
|
99
118
|
else
|
100
119
|
puts 'already uploaded for ' + self.class.name
|
101
120
|
end
|
@@ -110,5 +129,6 @@ module SimpleWorker
|
|
110
129
|
end
|
111
130
|
|
112
131
|
|
132
|
+
|
113
133
|
end
|
114
134
|
end
|
data/lib/simple_worker.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'appoxy_api'
|
2
2
|
require File.join(File.dirname(__FILE__), 'simple_worker', 'base')
|
3
3
|
require File.join(File.dirname(__FILE__), 'simple_worker', 'config')
|
4
|
+
require File.join(File.dirname(__FILE__), 'simple_worker', 'used_in_worker')
|
4
5
|
|
5
6
|
module SimpleWorker
|
6
7
|
|
@@ -29,6 +30,7 @@ module SimpleWorker
|
|
29
30
|
|
30
31
|
# Options:
|
31
32
|
# - :callback_url
|
33
|
+
# - :merge => array of files to merge in with this file
|
32
34
|
def upload(filename, class_name, options={})
|
33
35
|
|
34
36
|
# check whether it should upload again
|
@@ -41,6 +43,9 @@ module SimpleWorker
|
|
41
43
|
existing_md5 = IO.read(f)
|
42
44
|
puts 'existing_md5=' + existing_md5
|
43
45
|
end
|
46
|
+
|
47
|
+
filename = build_merged_file(filename, options[:merge]) if options[:merge]
|
48
|
+
|
44
49
|
# sys.classes[subclass].__file__
|
45
50
|
# puts '__FILE__=' + Base.subclass.__file__.to_s
|
46
51
|
md5 = Digest::MD5.hexdigest(File.read(filename))
|
@@ -61,6 +66,20 @@ module SimpleWorker
|
|
61
66
|
ret
|
62
67
|
end
|
63
68
|
|
69
|
+
def build_merged_file(filename, merge)
|
70
|
+
merge = merge.dup
|
71
|
+
merge.insert(0, filename)
|
72
|
+
fname2 = File.join(Dir.tmpdir(), File.basename(filename))
|
73
|
+
puts 'fname2=' + fname2
|
74
|
+
File.open(fname2, "w") do |f|
|
75
|
+
merge.each do |m|
|
76
|
+
f.write File.open(m, 'r') { |mo| mo.read }
|
77
|
+
f.write "\n\n"
|
78
|
+
end
|
79
|
+
end
|
80
|
+
fname2
|
81
|
+
end
|
82
|
+
|
64
83
|
def add_sw_params(hash_to_send)
|
65
84
|
hash_to_send["sw_access_key"] = self.access_key
|
66
85
|
hash_to_send["sw_secret_key"] = self.secret_key
|
@@ -0,0 +1,21 @@
|
|
1
|
+
begin
|
2
|
+
require File.join(File.dirname(__FILE__), '../lib/simple_worker')
|
3
|
+
rescue Exception
|
4
|
+
require 'simple_worker'
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
class Model1
|
9
|
+
attr_accessor :heidi, :ho
|
10
|
+
|
11
|
+
include SimpleWorker::UsedInWorker
|
12
|
+
|
13
|
+
def say_hello
|
14
|
+
log "Hi there sir"
|
15
|
+
end
|
16
|
+
|
17
|
+
# testk laksdfj klasj df
|
18
|
+
def test
|
19
|
+
log 'test'
|
20
|
+
end
|
21
|
+
end
|
data/test/test_worker.rb
CHANGED
@@ -11,7 +11,7 @@ class TestWorker < SimpleWorker::Base
|
|
11
11
|
def run(data=nil)
|
12
12
|
log 'running the runner for leroy '.upcase + ' with data: ' + data.inspect
|
13
13
|
|
14
|
-
log 's3_key instance_variable = ' + self.s3_key
|
14
|
+
log 's3_key instance_variable = ' + self.s3_key.to_s
|
15
15
|
|
16
16
|
@times = data["times"].to_i
|
17
17
|
@times.times do |i|
|
data/test/test_worker_2.rb
CHANGED
@@ -7,8 +7,11 @@ end
|
|
7
7
|
# Bump for new checksum.
|
8
8
|
class TestWorker2 < SimpleWorker::Base
|
9
9
|
|
10
|
+
merge "models/model_1.rb"
|
11
|
+
|
10
12
|
attr_accessor :s3_key, :times, :x
|
11
13
|
|
14
|
+
|
12
15
|
def who_am_i2?
|
13
16
|
return self.class.name
|
14
17
|
end
|
@@ -22,6 +25,9 @@ class TestWorker2 < SimpleWorker::Base
|
|
22
25
|
sleep 1
|
23
26
|
set_progress(:percent=> (i / times * 100))
|
24
27
|
end
|
28
|
+
m1 = Model1.new
|
29
|
+
log "I made a new model1"
|
30
|
+
m1.say_hello
|
25
31
|
end
|
26
32
|
|
27
33
|
def set_complete(params=nil)
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: simple_worker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
9
|
+
- 3
|
10
|
+
version: 0.3.3
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Travis Reeder
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-05-
|
18
|
+
date: 2010-05-24 00:00:00 -07:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: appoxy_api
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
27
30
|
segments:
|
28
31
|
- 0
|
29
32
|
version: "0"
|
@@ -41,7 +44,14 @@ files:
|
|
41
44
|
- lib/simple_worker.rb
|
42
45
|
- lib/simple_worker/base.rb
|
43
46
|
- lib/simple_worker/config.rb
|
47
|
+
- lib/simple_worker/used_in_worker.rb
|
44
48
|
- README.markdown
|
49
|
+
- test/models/model_1.rb
|
50
|
+
- test/scheduled_worker.rb
|
51
|
+
- test/test_inheritance.rb
|
52
|
+
- test/test_simple_worker.rb
|
53
|
+
- test/test_worker.rb
|
54
|
+
- test/test_worker_2.rb
|
45
55
|
has_rdoc: true
|
46
56
|
homepage: http://github.com/appoxy/simple_worker
|
47
57
|
licenses: []
|
@@ -52,27 +62,32 @@ rdoc_options:
|
|
52
62
|
require_paths:
|
53
63
|
- lib
|
54
64
|
required_ruby_version: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
55
66
|
requirements:
|
56
67
|
- - ">="
|
57
68
|
- !ruby/object:Gem::Version
|
69
|
+
hash: 3
|
58
70
|
segments:
|
59
71
|
- 0
|
60
72
|
version: "0"
|
61
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
62
75
|
requirements:
|
63
76
|
- - ">="
|
64
77
|
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
65
79
|
segments:
|
66
80
|
- 0
|
67
81
|
version: "0"
|
68
82
|
requirements: []
|
69
83
|
|
70
84
|
rubyforge_project:
|
71
|
-
rubygems_version: 1.3.
|
85
|
+
rubygems_version: 1.3.7
|
72
86
|
signing_key:
|
73
87
|
specification_version: 3
|
74
88
|
summary: Classified
|
75
89
|
test_files:
|
90
|
+
- test/models/model_1.rb
|
76
91
|
- test/scheduled_worker.rb
|
77
92
|
- test/test_inheritance.rb
|
78
93
|
- test/test_simple_worker.rb
|