simple_worker 0.3.9 → 0.3.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -104,17 +104,50 @@ module SimpleWorker
104
104
  SimpleWorker.service.schedule_status(schedule_id)
105
105
  end
106
106
 
107
+ # Callbacks for developer
108
+ def before_upload
109
+
110
+ end
111
+
112
+ def after_upload
113
+
114
+ end
115
+
116
+ def before_run
117
+
118
+ end
119
+ def after_run
120
+
121
+ end
122
+
107
123
  private
108
-
124
+
109
125
  def upload_if_needed
110
126
 
127
+ before_upload
128
+
111
129
  puts 'upload_if_needed'
130
+ # Todo, watch for this file changing or something so we can reupload
112
131
  unless uploaded?
113
132
  subclass = self.class
114
133
  rfile = subclass.instance_variable_get(:@caller_file) # Base.caller_file # File.expand_path(Base.subclass)
115
134
  puts 'rfile=' + rfile.inspect
116
135
  puts 'self.class.name=' + subclass.name
117
- SimpleWorker.service.upload(rfile, subclass.name, :merge=>self.class.instance_variable_get(:@merged))
136
+ merged = self.class.instance_variable_get(:@merged)
137
+ puts 'merged1=' + merged.inspect
138
+ superclass = subclass
139
+ # Also get merged from subclasses up to SimpleWorker::Base
140
+ while (superclass = superclass.superclass)
141
+ puts 'superclass=' + superclass.name
142
+ break if superclass.name == SimpleWorker::Base.name
143
+ super_merged = superclass.instance_variable_get(:@merged)
144
+ # puts 'merging caller file: ' + superclass.instance_variable_get(:@caller_file).inspect
145
+ super_merged << superclass.instance_variable_get(:@caller_file)
146
+ merged = super_merged + merged
147
+ puts 'merged with superclass=' + merged.inspect
148
+
149
+ end
150
+ SimpleWorker.service.upload(rfile, subclass.name, :merge=>merged)
118
151
  self.class.instance_variable_set(:@uploaded, true)
119
152
  else
120
153
  puts 'already uploaded for ' + self.class.name
@@ -126,6 +159,8 @@ module SimpleWorker
126
159
  Kernel.const_get(mw[1]).new.upload
127
160
  # SimpleWorker.service.upload(mw[0], mw[1])
128
161
  end
162
+
163
+ after_upload
129
164
  end
130
165
 
131
166
  def sw_get_data
@@ -137,6 +172,5 @@ module SimpleWorker
137
172
  end
138
173
 
139
174
 
140
-
141
175
  end
142
176
  end
data/lib/simple_worker.rb CHANGED
@@ -68,9 +68,10 @@ module SimpleWorker
68
68
 
69
69
  def build_merged_file(filename, merge)
70
70
  merge = merge.dup
71
- merge.insert(0, filename)
71
+ merge << filename
72
72
  fname2 = File.join(Dir.tmpdir(), File.basename(filename))
73
73
  puts 'fname2=' + fname2
74
+ puts 'merged_file_array=' + merge.inspect
74
75
  File.open(fname2, "w") do |f|
75
76
  merge.each do |m|
76
77
  f.write File.open(m, 'r') { |mo| mo.read }
data/test/test_base.rb ADDED
@@ -0,0 +1,31 @@
1
+ require 'test/unit'
2
+ require 'yaml'
3
+ begin
4
+ require File.join(File.dirname(__FILE__), '../lib/simple_worker')
5
+ rescue Exception => ex
6
+ puts ex.message
7
+ require 'simple_worker'
8
+ end
9
+ require File.join(File.dirname(__FILE__), "./test_worker")
10
+ require File.join(File.dirname(__FILE__), "./test_worker_2")
11
+ require File.join(File.dirname(__FILE__), "./test_worker_3")
12
+
13
+ class TestBase < Test::Unit::TestCase
14
+
15
+ def setup
16
+ @config = YAML::load(File.open(File.expand_path("~/.test-configs/simple_worker.yml")))
17
+ #puts @config.inspect
18
+ @access_key = @config['simple_worker']['access_key']
19
+ @secret_key = @config['simple_worker']['secret_key']
20
+
21
+ @worker = SimpleWorker::Service.new(@access_key, @secret_key)
22
+ @worker.host = "http://localhost:3000/api/"
23
+
24
+ # new style
25
+ SimpleWorker.configure do |config|
26
+ config.access_key = @access_key
27
+ config.secret_key = @secret_key
28
+ config.host = "http://localhost:3000/api/"
29
+ end
30
+ end
31
+ end
@@ -1,7 +1,19 @@
1
+ require 'test_base'
1
2
 
3
+ class TestInheritance < TestBase
2
4
 
3
- require File.join(File.dirname(__FILE__), "./test_worker_2")
5
+ def test_who_am_i
4
6
 
5
- worker = TestWorker2.new
6
- puts worker.who_am_i?
7
- puts worker.who_am_i2?
7
+ worker = TestWorker2.new
8
+ puts "1: " + worker.who_am_i?
9
+ puts "2: " + worker.who_am_i2?
10
+
11
+
12
+ end
13
+
14
+ def test_multi_subs
15
+ t3 = TestWorker3.new
16
+ t3.queue
17
+ end
18
+
19
+ end
@@ -1,36 +1,9 @@
1
- require 'test/unit'
2
- require 'yaml'
3
- begin
4
- require File.join(File.dirname(__FILE__), '../lib/simple_worker')
5
- rescue Exception => ex
6
- puts ex.message
7
- require 'simple_worker'
8
- end
9
- require File.join(File.dirname(__FILE__), "./test_worker")
10
- require File.join(File.dirname(__FILE__), "./test_worker_2")
11
-
12
- class SimpleWorkerTests < Test::Unit::TestCase
13
-
14
- def setup
15
- @config = YAML::load(File.open(File.expand_path("~/.test-configs/simple_worker.yml")))
16
- #puts @config.inspect
17
- @access_key = @config['simple_worker']['access_key']
18
- @secret_key = @config['simple_worker']['secret_key']
19
1
 
20
- @worker = SimpleWorker::Service.new(@access_key, @secret_key)
21
- @worker.host = "http://localhost:3000/api/"
22
2
 
23
- # new style
24
- SimpleWorker.configure do |config|
25
- config.access_key = @access_key
26
- config.secret_key = @secret_key
27
- config.host = "http://localhost:3000/api/"
28
- end
29
- end
3
+ require 'test_base'
30
4
 
31
- def teardown
5
+ class SimpleWorkerTests < TestBase
32
6
 
33
- end
34
7
 
35
8
  def test_new_worker_style
36
9
  # Add something to queue, get task ID back
@@ -0,0 +1,19 @@
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
+ require 'test_worker_2'
8
+
9
+ class TestWorker3 < TestWorker2
10
+
11
+
12
+ attr_accessor :s3_key, :times
13
+
14
+ def run()
15
+
16
+ end
17
+
18
+ end
19
+
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: 1
4
+ hash: 7
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 3
9
- - 9
10
- version: 0.3.9
9
+ - 10
10
+ version: 0.3.10
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-06-03 00:00:00 -07:00
18
+ date: 2010-08-24 00:00:00 -07:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -49,10 +49,12 @@ files:
49
49
  - test/models/model_1.rb
50
50
  - test/scheduled_worker.rb
51
51
  - test/second_worker.rb
52
+ - test/test_base.rb
52
53
  - test/test_inheritance.rb
53
54
  - test/test_simple_worker.rb
54
55
  - test/test_worker.rb
55
56
  - test/test_worker_2.rb
57
+ - test/test_worker_3.rb
56
58
  has_rdoc: true
57
59
  homepage: http://github.com/appoxy/simple_worker
58
60
  licenses: []
@@ -91,7 +93,9 @@ test_files:
91
93
  - test/models/model_1.rb
92
94
  - test/scheduled_worker.rb
93
95
  - test/second_worker.rb
96
+ - test/test_base.rb
94
97
  - test/test_inheritance.rb
95
98
  - test/test_simple_worker.rb
96
99
  - test/test_worker.rb
97
100
  - test/test_worker_2.rb
101
+ - test/test_worker_3.rb