simple_worker 0.7.0.beta.3 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -104,6 +104,16 @@ action in your application. This is almost the same as queuing your worker.
104
104
  worker.body = "This is the body"
105
105
  worker.schedule(:start_at=>1.hours.since)
106
106
 
107
+ By default, if you call `schedule` more than once for the same worker class, the new schedule will replace the old one. If you'd
108
+ like multiple schedules for the same class, provide a `:name` parameter:
109
+
110
+ worker.schedule(:name=>"EmailWorkerDaily", :start_at=>......)
111
+
112
+ You can also set priority for scheduled jobs:
113
+
114
+ worker.schedule(:priority=>1, ....)
115
+
116
+
107
117
  Check Status
108
118
  ------------
109
119
 
@@ -275,3 +285,8 @@ Then in your worker, you would have the attributes defined:
275
285
 
276
286
  attr_accessor :db_user, :db_pass
277
287
 
288
+
289
+ Development of the Gem
290
+ ----------------------
291
+
292
+ Join the discussion group at: https://groups.google.com/forum/?hl=en#!forum/simple_worker
data/lib/railtie.rb CHANGED
@@ -6,8 +6,20 @@ require 'rails'
6
6
  module SimpleWorker
7
7
  class Railtie < Rails::Railtie
8
8
 
9
+ @gems_to_skip = ['actionmailer', 'actionpack', 'activemodel', 'activeresource', 'activesupport',
10
+ 'bundler',
11
+ 'mail',
12
+ 'mysql2',
13
+ 'rails',
14
+ 'tzinfo' # HUGE!
15
+ ]
16
+
17
+ def self.gems_to_skip
18
+ @gems_to_skip
19
+ end
20
+
9
21
  initializer "simple_worker.configure_rails_initialization" do |app|
10
- SimpleWorker.logger.info "Initializing SimpleWorker for Rails 3..."
22
+ SimpleWorker.logger.info "Initializing SimpleWorker for Rails 3..."
11
23
  start_time = Time.now
12
24
  SimpleWorker.configure do |c2|
13
25
  models_path = File.join(Rails.root, 'app/models/*.rb')
@@ -29,23 +41,55 @@ module SimpleWorker
29
41
 
30
42
  def get_required_gems
31
43
  gems_in_gemfile = Bundler.environment.dependencies.select { |d| d.groups.include?(:default) }
44
+ SimpleWorker.logger.debug 'gems in gemfile=' + gems_in_gemfile.inspect
32
45
  gems =[]
33
46
  specs = Bundler.load.specs
34
47
  SimpleWorker.logger.debug 'Bundler specs=' + specs.inspect
35
- gems_in_gemfile.each do |dep|
36
- next if dep.name=='rails' #monkey patch
37
- gem_info = {:name=>dep.name, :version=>dep.requirement}
38
- gem_info.merge!({:require=>dep.autorequire.join}) if dep.autorequire
39
- spec = specs.find { |g| g.name==gem_info[:name] }
40
- if spec
41
- gem_info[:version] = spec.version.to_s
42
- gems << gem_info
43
- else
44
- SimpleWorker.logger.warn "Could not find gem spec for #{gem_info[:name]}"
48
+ SimpleWorker.logger.debug "gems_to_skip=" + self.class.gems_to_skip.inspect
49
+ specs.each do |spec|
50
+ SimpleWorker.logger.debug 'spec.name=' + spec.name.inspect
51
+ SimpleWorker.logger.debug 'spec=' + spec.inspect
52
+ p spec.methods
53
+ if self.class.gems_to_skip.include?(spec.name)
54
+ SimpleWorker.logger.debug "Skipping #{spec.name}"
55
+ next
56
+ end
57
+ # next if dep.name=='rails' #monkey patch
58
+ gem_info = {:name=>spec.name, :version=>spec.version}
59
+ gem_info[:auto_merged] = true
60
+ # Now find dependency in gemfile in case user set the require
61
+ dep = gems_in_gemfile.find { |g| g.name == gem_info[:name] }
62
+ if dep
63
+ SimpleWorker.logger.debug 'dep found in gemfile: ' + dep.inspect
64
+ SimpleWorker.logger.debug 'autorequire=' + dep.autorequire.inspect
65
+ gem_info[:require] = dep.autorequire if dep.autorequire
66
+ # spec = specs.find { |g| g.name==gem_info[:name] }
45
67
  end
68
+ gem_info[:version] = spec.version.to_s
69
+ gems << gem_info
70
+ path = SimpleWorker::Service.get_gem_path(gem_info)
71
+ if path
72
+ gem_info[:path] = path
73
+ if gem_info[:require].nil? && dep
74
+ # see if we should try to require this in our worker
75
+ require_path = gem_info[:path] + "/lib/#{gem_info[:name]}.rb"
76
+ SimpleWorker.logger.debug "require_path=" + require_path
77
+ if File.exists?(require_path)
78
+ SimpleWorker.logger.debug "File exists for require"
79
+ gem_info[:require] = gem_info[:name]
80
+ else
81
+ SimpleWorker.logger.debug "no require"
82
+ # gem_info[:no_require] = true
83
+ end
84
+ end
85
+ end
86
+ # else
87
+ # SimpleWorker.logger.warn "Could not find gem spec for #{gem_info[:name]}"
88
+ # raise "Could not find gem spec for #{gem_info[:name]}"
89
+ # end
46
90
  end
47
91
  gems
48
92
  end
49
- end
50
93
 
94
+ end
51
95
  end
@@ -15,6 +15,7 @@ module SimpleWorker
15
15
  @merged_mailers = []
16
16
  @merged_folders = {}
17
17
  @unmerged = []
18
+ @unmerged_gems = []
18
19
 
19
20
  def reset!
20
21
  @merged = []
@@ -23,6 +24,7 @@ module SimpleWorker
23
24
  @merged_mailers = []
24
25
  @merged_folders = {}
25
26
  @unmerged = []
27
+ @unmerged_gems = []
26
28
  end
27
29
 
28
30
  def inherited(subclass)
@@ -68,19 +70,33 @@ module SimpleWorker
68
70
  f
69
71
  end
70
72
 
71
- # merges the specified gem.
72
- def merge_gem(gem_name, version=nil)
73
+ # merges the specified gem.
74
+ def merge_gem(gem_name, options={})
73
75
  gem_info = {:name=>gem_name, :merge=>true}
74
- if version.is_a?(Hash)
75
- gem_info.merge!(version)
76
+ if options.is_a?(Hash)
77
+ gem_info.merge!(options)
76
78
  else
77
- gem_info[:version] = version
79
+ gem_info[:version] = options
78
80
  end
81
+ path = SimpleWorker::Service.get_gem_path(gem_info)
82
+ SimpleWorker.logger.debug "Gem path=#{path}"
83
+ if !path
84
+ raise "Gem path not found for #{gem_name}"
85
+ end
86
+ gem_info[:path] = path
79
87
  @merged_gems << gem_info
80
- require gem_info[:require] || gem_name
88
+ puts 'before require ' + (options[:require] || gem_name)
89
+ require options[:require] || gem_name
90
+ puts 'required yo'
91
+ end
92
+
93
+
94
+ def unmerge_gem(gem_name)
95
+ gem_info = {:name=>gem_name}
96
+ @unmerged_gems << gem_info
81
97
  end
82
98
 
83
- #merge action_mailer mailers
99
+ #merge action_mailer mailers
84
100
  def merge_mailer(mailer, params={})
85
101
  check_for_file mailer
86
102
  basename = File.basename(mailer, File.extname(mailer))
@@ -98,8 +114,8 @@ module SimpleWorker
98
114
  SimpleWorker.logger.info "Merged folders! #{@merged_folders.inspect}"
99
115
  end
100
116
 
101
- # merges the specified files.
102
- # todo: don't allow multiple files per merge, just one like require
117
+ # merges the specified files.
118
+ # todo: don't allow multiple files per merge, just one like require
103
119
  def merge(*files)
104
120
  files.each do |f|
105
121
  f = check_for_file(f)
@@ -107,8 +123,8 @@ module SimpleWorker
107
123
  end
108
124
  end
109
125
 
110
- # Opposite of merge, this will omit the files you specify from being merged in. Useful in Rails apps
111
- # where a lot of things are auto-merged by default like your models.
126
+ # Opposite of merge, this will omit the files you specify from being merged in. Useful in Rails apps
127
+ # where a lot of things are auto-merged by default like your models.
112
128
  def unmerge(*files)
113
129
  files.each do |f|
114
130
  f = check_for_file(f)
@@ -121,11 +137,11 @@ module SimpleWorker
121
137
  s[-suffix.length, suffix.length] == suffix
122
138
  end
123
139
 
124
- # Use this to merge in other workers. These are treated differently the normal merged files because
125
- # they will be uploaded separately and treated as distinctly separate workers.
126
- #
127
- # file: This is the path to the file, just like merge.
128
- # class_name: eg: 'MyWorker'.
140
+ # Use this to merge in other workers. These are treated differently the normal merged files because
141
+ # they will be uploaded separately and treated as distinctly separate workers.
142
+ #
143
+ # file: This is the path to the file, just like merge.
144
+ # class_name: eg: 'MyWorker'.
129
145
  def merge_worker(file, class_name)
130
146
  # puts 'merge_worker in ' + self.name
131
147
  merge(file)
@@ -154,7 +170,7 @@ module SimpleWorker
154
170
  self.class.instance_variable_defined?(:@uploaded) && self.class.instance_variable_get(:@uploaded)
155
171
  end
156
172
 
157
- # Call this if you want to run locally and get some extra features from this gem like global attributes.
173
+ # Call this if you want to run locally and get some extra features from this gem like global attributes.
158
174
  def run_local
159
175
  # puts 'run_local'
160
176
  set_auto_attributes
@@ -200,15 +216,15 @@ module SimpleWorker
200
216
  queue(options)
201
217
  end
202
218
 
203
- # Call this to queue up your job to SimpleWorker cloud.
204
- # options:
205
- # :priority => 0,1 or 2. Default is 0.
206
- # :recursive => true/false. Default is false. If you queue up a worker that is the same class as the currently
207
- # running worker, it will be rejected unless you set this explicitly so we know you meant to do it.
219
+ # Call this to queue up your job to SimpleWorker cloud.
220
+ # options:
221
+ # :priority => 0, 1 or 2. Default is 0.
222
+ # :recursive => true/false. Default is false. If you queue up a worker that is the same class as the currently
223
+ # running worker, it will be rejected unless you set this explicitly so we know you meant to do it.
208
224
  def queue(options={})
209
225
  # puts 'in queue'
210
226
  set_auto_attributes
211
- upload_if_needed
227
+ upload_if_needed(options)
212
228
 
213
229
  response = SimpleWorker.service.queue(self.class.name, sw_get_data, options)
214
230
  # puts 'queue response=' + response.inspect
@@ -217,6 +233,7 @@ module SimpleWorker
217
233
  response
218
234
  end
219
235
 
236
+ # Receive the status of your worker.
220
237
  def status
221
238
  check_service
222
239
  if task_id
@@ -240,9 +257,9 @@ module SimpleWorker
240
257
  false
241
258
  end
242
259
 
243
- # will return after job has completed or errored out.
244
- # Returns status.
245
- # todo: add a :timeout option
260
+ # will return after job has completed or errored out.
261
+ # Returns status.
262
+ # todo: add a :timeout option
246
263
  def wait_until_complete
247
264
  check_service
248
265
  tries = 0
@@ -264,19 +281,20 @@ module SimpleWorker
264
281
  upload_if_needed
265
282
  end
266
283
 
267
- #
268
- # schedule: hash of scheduling options that can include:
269
- # Required:
270
- # - start_at: Time of first run - DateTime or Time object.
271
- # Optional:
272
- # - run_every: Time in seconds between runs. If ommitted, task will only run once.
273
- # - delay_type: Fixed Rate or Fixed Delay. Default is fixed_delay.
274
- # - end_at: Scheduled task will stop running after this date (optional, if ommitted, runs forever or until cancelled)
275
- # - run_times: Task will run exactly :run_times. For instance if :run_times is 5, then the task will run 5 times.
276
- #
284
+ #
285
+ # schedule: hash of scheduling options that can include:
286
+ # Required:
287
+ # - start_at: Time of first run - DateTime or Time object.
288
+ # Optional:
289
+ # - run_every: Time in seconds between runs. If ommitted, task will only run once.
290
+ # - delay_type: Fixed Rate or Fixed Delay. Default is fixed_delay.
291
+ # - end_at: Scheduled task will stop running after this date (optional, if ommitted, runs forever or until cancelled)
292
+ # - run_times: Task will run exactly :run_times. For instance if :run_times is 5, then the task will run 5 times.
293
+ # - name: Provide a name for the schedule, defaults to class name. Use this if you want more than one schedule per worker class.
294
+ #
277
295
  def schedule(schedule)
278
296
  set_global_attributes
279
- upload_if_needed
297
+ upload_if_needed(schedule)
280
298
 
281
299
  response = SimpleWorker.service.schedule(self.class.name, sw_get_data, schedule)
282
300
  # puts 'schedule response=' + response.inspect
@@ -288,12 +306,12 @@ module SimpleWorker
288
306
  SimpleWorker.service.schedule_status(schedule_id)
289
307
  end
290
308
 
291
- # Retrieves the log for this worker from the SimpleWorker service.
309
+ # Retrieves the log for this worker from the SimpleWorker service.
292
310
  def get_log
293
311
  SimpleWorker.service.log(task_id)
294
312
  end
295
313
 
296
- # Callbacks for developer
314
+ # Callbacks for developer
297
315
  def before_upload
298
316
 
299
317
  end
@@ -337,31 +355,31 @@ module SimpleWorker
337
355
  superclass = subclass
338
356
  # Also get merged from subclasses up to SimpleWorker::Base
339
357
  while (superclass = superclass.superclass)
340
- #puts 'superclass=' + superclass.name
358
+ #puts 'superclass=' + superclass.name
341
359
  break if superclass.name == SimpleWorker::Base.name
342
360
  super_merged = superclass.instance_variable_get(:@merged)
343
- #puts 'merging caller file: ' + superclass.instance_variable_get(:@caller_file).inspect
361
+ #puts 'merging caller file: ' + superclass.instance_variable_get(:@caller_file).inspect
344
362
  super_merged << superclass.instance_variable_get(:@caller_file)
345
363
  merged = super_merged + merged
346
- #puts 'merged with superclass=' + merged.inspect
364
+ #puts 'merged with superclass=' + merged.inspect
347
365
  end
348
366
  return merged, rfile, subclass
349
367
  end
350
368
 
351
369
  def self.extract_merged_workers(worker)
352
370
  merged_workers = worker.class.instance_variable_get(:@merged_workers)
353
- SimpleWorker.logger.debug "Looking for merged_workers in #{worker.class.name}: #{merged_workers.inspect}"
371
+ SimpleWorker.logger.debug "Looking for merged_workers in #{worker.class.name}: #{merged_workers.inspect}"
354
372
  ret = []
355
373
  if merged_workers && merged_workers.size > 0
356
374
  merged_workers.each do |mw|
357
- SimpleWorker.logger.debug "merged worker found in #{worker.class.name}: #{mw.inspect}"
375
+ SimpleWorker.logger.debug "merged worker found in #{worker.class.name}: #{mw.inspect}"
358
376
  ret << mw[0]
359
377
  end
360
378
  end
361
379
  ret
362
380
  end
363
381
 
364
- def upload_if_needed
382
+ def upload_if_needed(options={})
365
383
  check_service
366
384
  SimpleWorker.service.check_config
367
385
 
@@ -369,7 +387,7 @@ module SimpleWorker
369
387
 
370
388
  merged = self.class.instance_variable_get(:@merged)
371
389
 
372
- # do merged_workers first because we need to get their subclasses and what not too
390
+ # do merged_workers first because we need to get their subclasses and what not too
373
391
  merged_workers = self.class.instance_variable_get(:@merged_workers)
374
392
  if merged_workers && merged_workers.size > 0
375
393
  SimpleWorker.logger.debug 'now uploading merged workers ' + merged_workers.inspect
@@ -408,7 +426,9 @@ module SimpleWorker
408
426
  end
409
427
  merged.uniq!
410
428
  merged_mailers.uniq!
411
- SimpleWorker.service.upload(rfile, subclass.name, :merge=>merged, :unmerge=>unmerged, :merged_gems=>merged_gems, :merged_mailers=>merged_mailers, :merged_folders=>merged_folders)
429
+ options_for_upload = {:merge=>merged, :unmerge=>unmerged, :merged_gems=>merged_gems, :merged_mailers=>merged_mailers, :merged_folders=>merged_folders}
430
+ options_for_upload[:name] = options[:name] if options[:name]
431
+ SimpleWorker.service.upload(rfile, subclass.name, options_for_upload)
412
432
  self.class.instance_variable_set(:@uploaded, true)
413
433
  else
414
434
  SimpleWorker.logger.debug 'Already uploaded for ' + self.class.name
@@ -422,12 +442,17 @@ module SimpleWorker
422
442
  data = {}
423
443
 
424
444
  payload = {}
445
+ # todo: should put these down a layer, eg: payload[:attributes]
425
446
  self.instance_variables.each do |iv|
426
447
  payload[iv] = instance_variable_get(iv)
427
448
  end
428
449
  data[:attr_encoded] = Base64.encode64(payload.to_json)
429
450
  data[:file_name] = File.basename(self.class.instance_variable_get(:@caller_file))
430
-
451
+ if defined?(Rails)
452
+ data[:rails] = {}
453
+ data[:rails]['env'] = Rails.env
454
+ data[:rails]['version'] = Rails.version
455
+ end
431
456
  config_data = SimpleWorker.config.get_atts_to_send
432
457
  data[:sw_config] = config_data
433
458
  return data
@@ -29,6 +29,8 @@ module SimpleWorker
29
29
  end
30
30
 
31
31
  def get_server_gems
32
+ return []
33
+ # skipping this now, don't want any server dependencies if possible
32
34
  self.server_gems = SimpleWorker.service.get_server_gems unless self.server_gems
33
35
  self.server_gems
34
36
  end
@@ -13,7 +13,6 @@ module SimpleWorker
13
13
  attr_accessor :config
14
14
 
15
15
  def initialize(access_key, secret_key, options={})
16
- SimpleWorker.logger.info 'Starting SimpleWorker::Service...'
17
16
  if options[:config]
18
17
  self.config = options[:config]
19
18
  else
@@ -24,14 +23,16 @@ module SimpleWorker
24
23
  end
25
24
  super("http://api.simpleworker.com/api/", access_key, secret_key, options)
26
25
  self.host = self.config.host if self.config && self.config.host
26
+ SimpleWorker.logger.info 'SimpleWorker initialized.'
27
27
  end
28
28
 
29
29
  # Options:
30
30
  # - :callback_url
31
31
  # - :merge => array of files to merge in with this file
32
32
  def upload(filename, class_name, options={})
33
+ name = options[:name] || class_name
33
34
  # puts "Uploading #{class_name}"
34
- # check whether it should upload again
35
+ # check whether it should upload again
35
36
  tmp = Dir.tmpdir()
36
37
  md5file = "simple_worker_#{class_name.gsub("::", ".")}_#{access_key[0, 8]}.md5"
37
38
  existing_md5 = nil
@@ -46,33 +47,25 @@ module SimpleWorker
46
47
  SimpleWorker.logger.info "Uploading #{class_name}, code modified."
47
48
  File.open(f, 'w') { |f| f.write(md5) }
48
49
  new_code = true
50
+ # todo: delete md5 file if error occurs during upload process
49
51
  else
50
52
  # puts "#{class_name}: same code, not uploading"
51
53
  return
52
54
  end
53
55
 
54
-
55
56
  zip_filename = build_merged_file(filename, options[:merge], options[:unmerge], options[:merged_gems], options[:merged_mailers], options[:merged_folders])
56
-
57
- # sys.classes[subclass].__file__
58
- # puts '__FILE__=' + Base.subclass.__file__.to_s
59
- # puts "new md5=" + md5
60
-
57
+ SimpleWorker.logger.info 'file size to upload: ' + File.size(zip_filename).to_s
61
58
 
62
59
  if new_code
63
- # mystring = nil
64
- # file = File.open(filename, "r") do |f|
65
- # mystring = f.read
66
- # end
67
- # mystring = Base64.encode64(mystring)
68
- # puts 'code=' + mystring
69
60
  options = {
70
61
  "class_name"=>class_name,
71
- "name"=>class_name,
62
+ "name"=>name,
72
63
  "file_name"=> File.basename(filename)
73
64
  }
74
65
  #puts 'options for upload=' + options.inspect
66
+ SimpleWorker.logger.info "Uploading now..."
75
67
  ret = post_file("code/put", File.new(zip_filename), options)
68
+ SimpleWorker.logger.info "Done uploading."
76
69
  ret
77
70
  end
78
71
  end
@@ -82,8 +75,9 @@ module SimpleWorker
82
75
  JSON.parse(hash["gems"])
83
76
  end
84
77
 
85
- def get_gem_path(gem_info)
86
- gem_name =(gem_info[:require] || gem_info[:name].match(/^[a-zA-Z0-9\-_]+/)[0])
78
+ def self.get_gem_path(gem_info)
79
+ # gem_name =(gem_info[:require] || gem_info[:name].match(/^[a-zA-Z0-9\-_]+/)[0])
80
+ gem_name =(gem_info[:name].match(/^[a-zA-Z0-9\-_]+/)[0])
87
81
  puts "Searching for #{gem_name}..."
88
82
  gems= Gem::Specification.respond_to?(:each) ? Gem::Specification.find_all_by_name(gem_name) : Gem::GemPathSearcher.new.find_all(gem_name)
89
83
  # gems = searcher.init_gemspecs.select { |gem| gem.name==gem_name }
@@ -91,14 +85,15 @@ module SimpleWorker
91
85
  gems = gems.select { |g| g.version.version==gem_info[:version] } if gem_info[:version]
92
86
  if !gems.empty?
93
87
  gem = gems.first
94
- gem.full_gem_path + "/lib"
88
+ gem.full_gem_path
95
89
  else
96
- nil
90
+ SimpleWorker.logger.warn "Gem file was not found for #{gem_name}, continuing anyways."
91
+ return nil
97
92
  end
98
93
  end
99
94
 
100
- def build_merged_file(filename, merge, unmerge, merged_gems, merged_mailers,merged_folders)
101
- # unless (merge && merge.size > 0) || (merged_gems && merged_gems.size > 0)
95
+ def build_merged_file(filename, merge, unmerge, merged_gems, merged_mailers, merged_folders)
96
+ # unless (merge && merge.size > 0) || (rged_gems && merged_gems.size > 0)
102
97
  # return filename
103
98
  # end
104
99
  merge = merge.nil? ? [] : merge.dup
@@ -111,20 +106,47 @@ module SimpleWorker
111
106
  merge.uniq!
112
107
  tmp_file = File.join(Dir.tmpdir(), File.basename(filename))
113
108
  File.open(tmp_file, "w") do |f|
109
+ # add some rails stuff if using Rails
110
+ if defined?(Rails)
111
+ f.write "module Rails
112
+ def self.version
113
+ '#{Rails.version}'
114
+ end
115
+ def self.env
116
+ '#{Rails.env}'
117
+ end
118
+ end
119
+ "
120
+
121
+ end
114
122
  if SimpleWorker.config.extra_requires
115
123
  SimpleWorker.config.extra_requires.each do |r|
116
124
  f.write "require '#{r}'\n"
117
125
  end
118
126
  end
119
127
  if merged_mailers && !merged_mailers.empty?
128
+ # todo: isn't 'action_mailer already required in railtie?
120
129
  f.write "require 'action_mailer'\n"
121
130
  f.write "ActionMailer::Base.prepend_view_path('templates')\n"
122
131
  end
123
132
  if SimpleWorker.config.auto_merge
124
133
  if SimpleWorker.config.gems
125
134
  SimpleWorker.config.gems.each do |gem|
126
- f.write "$LOAD_PATH << File.join(File.dirname(__FILE__), '/gems/#{gem[:name]}')\n" if gem[:merge]
127
- f.write "require '#{gem[:require]||gem[:name]}'\n"
135
+ puts "Bundling gem #{gem[:name]}..."
136
+ f.write "$LOAD_PATH << File.join(File.dirname(__FILE__), '/gems/#{gem[:name]}/lib')\n" if gem[:merge]
137
+ # unless gem[:no_require]
138
+ puts 'writing requires: ' + gem[:require].inspect
139
+ if gem[:require].nil?
140
+ gem[:require] = []
141
+ elsif gem[:require].is_a?(String)
142
+ gem[:require] = [gem[:require]]
143
+ end
144
+ puts gem[:require].inspect
145
+ gem[:require].each do |r|
146
+ puts 'adding require to file ' + r.to_s
147
+ f.write "require '#{r}'\n"
148
+ end
149
+ # end
128
150
  end
129
151
  end
130
152
  if SimpleWorker.config.models
@@ -145,8 +167,8 @@ module SimpleWorker
145
167
  # puts "merge after uniq! " + merge.inspect
146
168
 
147
169
  fname2 = tmp_file + ".zip"
148
- # puts 'fname2=' + fname2
149
- # puts 'merged_file_array=' + merge.inspect
170
+ # puts 'fname2=' + fname2
171
+ # puts 'merged_file_array=' + merge.inspect
150
172
  #File.open(fname2, "w") do |f|
151
173
  File.delete(fname2) if File.exist?(fname2)
152
174
  Zip::ZipFile.open(fname2, 'w') do |f|
@@ -154,27 +176,35 @@ module SimpleWorker
154
176
  merged_gems.each do |gem|
155
177
  next unless gem[:merge]
156
178
  # puts 'gem=' + gem.inspect
157
- path = get_gem_path(gem)
179
+ path = gem[:path] # get_gem_path(gem)
158
180
  if path
159
181
  SimpleWorker.logger.debug "Collecting gem #{path}"
160
- Dir["#{path}/**/**"].each do |file|
182
+ Dir["#{path}/*", "#{path}/lib/**/**"].each do |file|
183
+ # todo: could check if directory and it not lib, skip it
184
+ puts 'file=' + file.inspect
161
185
  # puts 'gem2=' + gem.inspect
162
186
  zdest = "gems/#{gem[:name]}/#{file.sub(path+'/', '')}"
163
187
  # puts 'gem file=' + file.to_s
164
- # puts 'zdest=' + zdest
188
+ puts 'zdest=' + zdest
165
189
  f.add(zdest, file)
166
190
  end
167
191
  else
168
- raise "Gem #{gem[:name]} #{gem[:version]} was not found."
192
+ if gem[:auto_merged]
193
+ # todo: should only continue if the gem was auto merged.
194
+ SimpleWorker.logger.warn "Gem #{gem[:name]} #{gem[:version]} was not found, continuing anyways."
195
+ else
196
+ raise "Gem #{gem[:name]} #{gem[:version]} was not found, continuing anyways."
197
+ end
198
+
169
199
  end
170
200
  end
171
- end
201
+ end
172
202
  if merged_folders && merged_folders.size > 0
173
203
  merged_folders.each do |folder, files|
174
204
  SimpleWorker.logger.debug "Collecting folder #{folder}"
175
205
  if files and files.size>0
176
206
  files.each do |file|
177
- zdest = "#{Digest::MD5.hexdigest(folder)}/#{file.sub(':','_').sub('/','_')}"
207
+ zdest = "#{Digest::MD5.hexdigest(folder)}/#{file.sub(':', '_').sub('/', '_')}"
178
208
  puts 'put file to=' + zdest
179
209
  f.add(zdest, file)
180
210
  end
@@ -227,10 +257,11 @@ module SimpleWorker
227
257
  if !data.is_a?(Array)
228
258
  data = [data]
229
259
  end
230
- # p data
260
+ name = options[:name] || class_name
231
261
  hash_to_send = {}
232
262
  hash_to_send["payload"] = data
233
263
  hash_to_send["class_name"] = class_name
264
+ hash_to_send["name"] = name
234
265
  hash_to_send["priority"] = options[:priority] if options[:priority]
235
266
  hash_to_send["options"] = options
236
267
  add_sw_params(hash_to_send)
@@ -245,10 +276,10 @@ module SimpleWorker
245
276
  def queue_raw(class_name, data={})
246
277
  params = nil
247
278
  hash_to_send = data
248
- hash_to_send["class_name"] = class_name
279
+ hash_to_send["class_name"] = class_name unless hash_to_send["class_name"]
280
+ hash_to_send["name"] = class_name unless hash_to_send["name"]
249
281
  ret = post("queue/add", hash_to_send)
250
282
  ret
251
-
252
283
  end
253
284
 
254
285
  #
metadata CHANGED
@@ -1,8 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_worker
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: 6
5
- version: 0.7.0.beta.3
4
+ prerelease:
5
+ version: 0.7.0
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-07-05 00:00:00 Z
13
+ date: 2011-07-06 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: zip
@@ -70,9 +70,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
70
70
  required_rubygems_version: !ruby/object:Gem::Requirement
71
71
  none: false
72
72
  requirements:
73
- - - ">"
73
+ - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 1.3.1
75
+ version: "0"
76
76
  requirements: []
77
77
 
78
78
  rubyforge_project: