simple_worker 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -35,8 +35,8 @@ module SimpleWorker
35
35
  # caller_file = splits[0] + ":" + splits[1]
36
36
  caller_file = caller[0][0...(caller[0].index(":in"))]
37
37
  caller_file = caller_file[0...(caller_file.rindex(":"))]
38
- # puts 'caller_file=' + caller_file
39
- # don't need these class_variables anymore probably
38
+ # puts 'caller_file=' + caller_file
39
+ # don't need these class_variables anymore probably
40
40
  subclass.instance_variable_set(:@caller_file, caller_file)
41
41
 
42
42
  super
@@ -52,7 +52,7 @@ module SimpleWorker
52
52
  exists = true
53
53
  else
54
54
  # try relative
55
- # p caller
55
+ # p caller
56
56
  f2 = File.join(File.dirname(caller[3]), f)
57
57
  # puts 'f2=' + f2
58
58
  if File.exist? f2
@@ -95,8 +95,9 @@ module SimpleWorker
95
95
  files<<f
96
96
  end
97
97
  @merged_folders[path]=files unless files.empty?
98
- SimpleWorker.logger.info "Merged folders! #{@merged_folders.inspect}"
98
+ SimpleWorker.logger.info "Merged folders! #{@merged_folders.inspect}"
99
99
  end
100
+
100
101
  # merges the specified files.
101
102
  # todo: don't allow multiple files per merge, just one like require
102
103
  def merge(*files)
@@ -195,6 +196,10 @@ module SimpleWorker
195
196
  end
196
197
  end
197
198
 
199
+ def enqueue(options={})
200
+ queue(options)
201
+ end
202
+
198
203
  # Call this to queue up your job to SimpleWorker cloud.
199
204
  # options:
200
205
  # :priority => 0,1 or 2. Default is 0.
@@ -324,37 +329,57 @@ module SimpleWorker
324
329
  raise "SimpleWorker configuration not set." unless SimpleWorker.service
325
330
  end
326
331
 
332
+ def self.extract_superclasses_merges(worker, merged)
333
+ subclass = worker.class
334
+ rfile = subclass.instance_variable_get(:@caller_file) # Base.caller_file # File.expand_path(Base.subclass)
335
+ # puts 'subclass file=' + rfile.inspect
336
+ # puts 'subclass.name=' + subclass.name
337
+ superclass = subclass
338
+ # Also get merged from subclasses up to SimpleWorker::Base
339
+ while (superclass = superclass.superclass)
340
+ #puts 'superclass=' + superclass.name
341
+ break if superclass.name == SimpleWorker::Base.name
342
+ super_merged = superclass.instance_variable_get(:@merged)
343
+ #puts 'merging caller file: ' + superclass.instance_variable_get(:@caller_file).inspect
344
+ super_merged << superclass.instance_variable_get(:@caller_file)
345
+ merged = super_merged + merged
346
+ #puts 'merged with superclass=' + merged.inspect
347
+ end
348
+ return merged, rfile, subclass
349
+ end
350
+
327
351
  def upload_if_needed
328
352
  check_service
329
353
  SimpleWorker.service.check_config
330
354
 
331
355
  before_upload
332
356
 
357
+ merged = self.class.instance_variable_get(:@merged)
358
+
359
+ # do merged_workers first because we need to get their subclasses and what not too
360
+ merged_workers = self.class.instance_variable_get(:@merged_workers)
361
+ if merged_workers && merged_workers.size > 0
362
+ SimpleWorker.logger.debug 'now uploading merged workers ' + merged_workers.inspect
363
+ merged_workers.each do |mw|
364
+ SimpleWorker.logger.debug 'Instantiating and uploading ' + mw[1]
365
+ mw_instantiated = Kernel.const_get(mw[1]).new
366
+ mw_instantiated.upload
367
+
368
+ merged, rfile, subclass = SimpleWorker::Base.extract_superclasses_merges(mw_instantiated, merged)
369
+
370
+ end
371
+ end
372
+
333
373
  # puts 'upload_if_needed ' + self.class.name
334
- # Todo, watch for this file changing or something so we can reupload (if in dev env)
374
+ # Todo, watch for this file changing or something so we can reupload (if in dev env)
335
375
  unless uploaded?
336
- merged = self.class.instance_variable_get(:@merged)
337
376
  unmerged = self.class.instance_variable_get(:@unmerged)
338
377
  merged_gems = self.class.instance_variable_get(:@merged_gems)
339
378
  merged_mailers = self.class.instance_variable_get(:@merged_mailers)
340
379
  merged_folders = self.class.instance_variable_get(:@merged_folders)
341
380
  # puts 'merged1=' + merged.inspect
342
381
 
343
- subclass = self.class
344
- rfile = subclass.instance_variable_get(:@caller_file) # Base.caller_file # File.expand_path(Base.subclass)
345
- # puts 'subclass file=' + rfile.inspect
346
- # puts 'subclass.name=' + subclass.name
347
- superclass = subclass
348
- # Also get merged from subclasses up to SimpleWorker::Base
349
- while (superclass = superclass.superclass)
350
- # puts 'superclass=' + superclass.name
351
- break if superclass.name == SimpleWorker::Base.name
352
- super_merged = superclass.instance_variable_get(:@merged)
353
- # puts 'merging caller file: ' + superclass.instance_variable_get(:@caller_file).inspect
354
- super_merged << superclass.instance_variable_get(:@caller_file)
355
- merged = super_merged + merged
356
- # puts 'merged with superclass=' + merged.inspect
357
- end
382
+ merged, rfile, subclass = SimpleWorker::Base.extract_superclasses_merges(self, merged)
358
383
  if SimpleWorker.config.auto_merge
359
384
  puts "Auto merge Enabled"
360
385
  merged += SimpleWorker.config.models if SimpleWorker.config.models
@@ -369,21 +394,12 @@ module SimpleWorker
369
394
  end
370
395
  merged.uniq!
371
396
  merged_mailers.uniq!
372
- SimpleWorker.service.upload(rfile, subclass.name, :merge=>merged, :unmerge=>unmerged, :merged_gems=>merged_gems, :merged_mailers=>merged_mailers,:merged_folders=>merged_folders)
397
+ SimpleWorker.service.upload(rfile, subclass.name, :merge=>merged, :unmerge=>unmerged, :merged_gems=>merged_gems, :merged_mailers=>merged_mailers, :merged_folders=>merged_folders)
373
398
  self.class.instance_variable_set(:@uploaded, true)
374
399
  else
375
400
  SimpleWorker.logger.debug 'Already uploaded for ' + self.class.name
376
401
  end
377
- merged_workers = self.class.instance_variable_get(:@merged_workers)
378
- if merged_workers.size > 0
379
- # puts 'now uploading merged workers ' + merged_workers.inspect
380
- merged_workers.each do |mw|
381
- # to support merges in the secondary worker, we should instantiate it here, then call "upload"
382
- SimpleWorker.logger.debug 'Instantiating and uploading ' + mw[1]
383
- Kernel.const_get(mw[1]).new.upload
384
- # SimpleWorker.service.upload(mw[0], mw[1])
385
- end
386
- end
402
+
387
403
 
388
404
  after_upload
389
405
  end
@@ -215,6 +215,10 @@ module SimpleWorker
215
215
  end
216
216
  end
217
217
 
218
+ def enqueue(class_name, data={}, options={})
219
+ queue(class_name, data, options)
220
+ end
221
+
218
222
  # class_name: The class name of a previously upload class, eg: MySuperWorker
219
223
  # data: Arbitrary hash of your own data that your task will need to run.
220
224
  def queue(class_name, data={}, options={})
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: simple_worker
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.4
5
+ version: 0.6.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Travis Reeder
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-06-08 00:00:00 Z
13
+ date: 2011-06-18 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: zip
@@ -76,7 +76,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
76
  requirements: []
77
77
 
78
78
  rubyforge_project:
79
- rubygems_version: 1.7.2
79
+ rubygems_version: 1.8.5
80
80
  signing_key:
81
81
  specification_version: 3
82
82
  summary: The official SimpleWorker gem for http://www.simpleworker.com