iron_worker 2.3.12 → 2.3.13

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  ---
2
2
  :major: 2
3
3
  :minor: 3
4
- :patch: 12
4
+ :patch: 13
5
5
  :build: !!null
@@ -119,13 +119,20 @@ module IronWorker
119
119
  # Use this to merge in other workers. These are treated differently the normal merged files because
120
120
  # they will be uploaded separately and treated as distinctly separate workers.
121
121
  #
122
- # file: This is the path to the file, just like merge.
123
- # class_name: eg: 'MyWorker'.
122
+ # @param file [String] This is the path to the file, just like merge.
123
+ # @param class_name [String|Class] 'MyWorker' or just MyWorker.
124
+ # @return [Hash]
124
125
  def merge_worker(file, class_name)
125
- # puts 'merge_worker in ' + self.name
126
126
  ret = merge(file)
127
- ret[:class_name] = class_name
128
- #[File.expand_path(file), class_name]
127
+ ret[:class_name] = case class_name
128
+ when String
129
+ class_name.strip
130
+ when Class
131
+ class_name.name
132
+ else
133
+ IronWorker.service.logger.warn "merge_worker: only String or Class is expected as class_name"
134
+ class_name # probably user does know what is he doing
135
+ end
129
136
  @merged_workers[file] = ret
130
137
  ret
131
138
  end
@@ -242,11 +249,11 @@ module IronWorker
242
249
  end
243
250
 
244
251
  def is_local?
245
- !is_remote?
252
+ IronWorker.is_local?
246
253
  end
247
254
 
248
255
  def is_remote?
249
- false
256
+ IronWorker.is_remote?
250
257
  end
251
258
 
252
259
  # will return after job has completed or errored out.
@@ -33,7 +33,7 @@ module IronWorker
33
33
  :skip_auto_dependencies
34
34
 
35
35
  def self.system_gems
36
- ['bson_ext', 'curb', 'em-http-request', 'eventmachine', 'mysql2', 'net-scp', 'net-sftp', 'net-ssh', 'nokogiri', 'rmagick', 'sqlite3', 'typhoeus']
36
+ ['yajl-ruby', 'bson_ext', 'curb', 'em-http-request', 'eventmachine', 'mysql2', 'net-scp', 'net-sftp', 'net-ssh', 'nokogiri', 'rmagick', 'sqlite3', 'typhoeus']
37
37
  end
38
38
 
39
39
  def initialize
@@ -21,6 +21,22 @@ module IronWorker
21
21
  def task_data
22
22
  @task_data
23
23
  end
24
+
25
+ def payload=(td)
26
+ @payload = td
27
+ end
28
+
29
+ def payload
30
+ @payload
31
+ end
32
+
33
+ def is_local?
34
+ !is_remote?
35
+ end
36
+
37
+ def is_remote?
38
+ true
39
+ end
24
40
  end
25
41
 
26
42
  def self.disable_queueing()
@@ -82,15 +98,6 @@ module IronWorker
82
98
 
83
99
  end
84
100
 
85
- def is_remote?
86
- true
87
- end
88
-
89
- #:todo remove this method later, when new iron_worker gem will be released
90
- def is_local?
91
- !is_remote?
92
- end
93
-
94
101
  def log(str)
95
102
  puts str.to_s
96
103
  end
@@ -51,10 +51,12 @@ def init_runner(runner_class, job_data, user_dir, task_id)
51
51
  end
52
52
  runner = runner_class.new
53
53
  runner.instance_variable_set(:@task_id, task_id)
54
- runner.instance_variable_set(:@job_data, job_data)
55
- runner.instance_variable_set(:@sw_config, job_data['sw_config'])
54
+ if job_data
55
+ runner.instance_variable_set(:@job_data, job_data)
56
+ runner.instance_variable_set(:@sw_config, job_data['sw_config'])
57
+ runner.sw_set_data(job_data)
58
+ end
56
59
  runner.instance_variable_set(:@user_dir, user_dir)
57
- runner.sw_set_data(job_data)
58
60
  runner
59
61
  end
60
62
 
@@ -51,7 +51,7 @@ module IronWorker
51
51
 
52
52
  begin
53
53
 
54
- zip_filename = build_merged_file(filename, options[:merge], options[:unmerge], options[:merged_gems], options[:unmerged_gems], options[:merged_mailers], options[:merged_folders])
54
+ zip_filename = build_merged_file(filename, options[:merge], options[:unmerge], options[:merged_gems], options[:unmerged_gems], options[:merged_mailers], options[:merged_folders], class_name)
55
55
 
56
56
  # Check for code changes.
57
57
  zipfile = Zip::ZipFile.open(zip_filename, Zip::ZipFile::CREATE)
@@ -92,6 +92,9 @@ module IronWorker
92
92
  !Gem::GemPathSearcher.private_instance_methods.include?(:_deprecated_initialize)
93
93
  end
94
94
 
95
+ def webhook
96
+
97
+ end
95
98
 
96
99
  def self.get_gem_path(gem_info)
97
100
  # gem_name =(gem_info[:require] || gem_info[:name].match(/^[a-zA-Z0-9\-_\.]+/)[0])
@@ -143,7 +146,7 @@ module IronWorker
143
146
  dependendent_gems
144
147
  end
145
148
 
146
- def build_merged_file(filename, merged, unmerge, merged_gems, unmerged_gems, merged_mailers, merged_folders)
149
+ def build_merged_file(filename, merged, unmerge, merged_gems, unmerged_gems, merged_mailers, merged_folders, class_name)
147
150
 
148
151
  unmerged_gems ||= {}
149
152
 
@@ -157,8 +160,7 @@ module IronWorker
157
160
  end
158
161
  merged = merge
159
162
  IronWorker.logger.debug 'merged=' + merged.inspect
160
-
161
- merged_gems = merged_gems.merge(IronWorker.config.merged_gems)
163
+ merged_gems = IronWorker.config.merged_gems.merge(merged_gems)
162
164
  IronWorker.logger.debug 'merged_gems=' + merged_gems.inspect
163
165
 
164
166
  if config.skip_auto_dependencies
@@ -257,7 +259,10 @@ IronWorker.disable_queueing()
257
259
  #puts 'dirname=' + dirname.inspect
258
260
  Dir.chdir(dirname)
259
261
  # Load in job data
260
- job_data = JSON.load(File.open(task_data_file))
262
+ payload = IO.read(task_data_file)
263
+ IronWorker.payload = payload
264
+ begin
265
+ job_data = JSON.parse(payload)
261
266
  #puts 'payload=' + job_data.inspect
262
267
  sw_config = job_data['sw_config']
263
268
  IronWorker.task_data = job_data
@@ -272,6 +277,9 @@ if IronWorker.task_data['rails']
272
277
  end
273
278
  end
274
279
  end
280
+ rescue JSON::ParserError => ex
281
+ puts 'Payload is not json, raw payload can be accessed with IronWorker.payload.'
282
+ end
275
283
  ")
276
284
 
277
285
  if IronWorker.config.extra_requires
@@ -300,11 +308,13 @@ end
300
308
  f.write("require_relative '#{File.basename(filename)}'\n")
301
309
 
302
310
  f.write("
303
- runner_class = get_class_to_run(job_data['class_name'])
311
+ clz_name = '#{class_name}' # job_data['class_name']
312
+ runner_class = get_class_to_run(clz_name)
304
313
  IronWorker.running_class = runner_class
305
314
  runner = init_runner(runner_class, job_data, dirname, task_id)
315
+ if IronWorker.task_data
306
316
  init_worker_service_for_runner(job_data)
307
-
317
+ end
308
318
  # Now reenable after loading
309
319
  IronWorker.enable_queueing()
310
320
 
@@ -334,10 +344,10 @@ end
334
344
  # puts 'gem=' + gem.inspect
335
345
  path = gem[:path]
336
346
  if path
337
- IronWorker.logger.debug "Collecting gem #{path}"
347
+ #IronWorker.logger.debug "Collecting gem #{path}"
338
348
  paths_to_use = ["#{path}/*", "#{path}/lib/**/**"]
339
349
  if gem[:include_dirs]
340
- IronWorker.logger.debug "including extra dirs: " + gem[:include_dirs].inspect
350
+ #IronWorker.logger.debug "including extra dirs: " + gem[:include_dirs].inspect
341
351
  gem[:include_dirs].each do |dir|
342
352
  paths_to_use << "#{path}/#{dir}/**/**"
343
353
  end
@@ -345,11 +355,11 @@ end
345
355
  IronWorker.logger.debug 'paths_to_use: ' + paths_to_use.inspect
346
356
  Dir.glob(paths_to_use).each do |file|
347
357
  # todo: could check if directory and it not lib, skip it
348
- IronWorker.logger.debug 'file for gem=' + file.inspect
358
+ #IronWorker.logger.debug 'file for gem=' + file.inspect
349
359
  # puts 'gem2=' + gem.inspect
350
360
  zdest = "gems/#{gem[:name]}/#{file.sub(path+'/', '')}"
351
361
  # puts 'gem file=' + file.to_s
352
- IronWorker.logger.debug 'zip dest=' + zdest
362
+ #IronWorker.logger.debug 'zip dest=' + zdest
353
363
  f.add(zdest, file)
354
364
  end
355
365
  else
@@ -369,7 +379,7 @@ end
369
379
  if files and files.size>0
370
380
  files.each do |file|
371
381
  zdest = "#{Digest::MD5.hexdigest(folder)}/#{file.sub(':', '_').sub('/', '_')}"
372
- IronWorker.logger.debug 'put file to=' + zdest
382
+ #IronWorker.logger.debug 'put file to=' + zdest
373
383
  f.add(zdest, file)
374
384
  end
375
385
  end
@@ -471,7 +481,7 @@ end
471
481
  def queue(name, data={}, options={})
472
482
  puts "Queuing #{name}..."
473
483
  check_config
474
- if !data.is_a?(Array)
484
+ unless data.is_a?(Array)
475
485
  data = [data]
476
486
  end
477
487
  # Now we need to add class_name to the payload
@@ -493,7 +503,7 @@ end
493
503
  # todo: REMOVE THIS
494
504
  hash_to_send["rails_env"] = RAILS_ENV
495
505
  end
496
- return queue_raw(name, hash_to_send, options)
506
+ queue_raw(name, hash_to_send, options)
497
507
  end
498
508
 
499
509
  def queue_raw(name, data={}, options={})
data/lib/iron_worker.rb CHANGED
@@ -34,6 +34,14 @@ module IronWorker
34
34
  def api_version
35
35
  2
36
36
  end
37
+
38
+ def is_local?
39
+ !is_remote?
40
+ end
41
+
42
+ def is_remote?
43
+ false
44
+ end
37
45
  end
38
46
 
39
47
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iron_worker
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.3.12
4
+ version: 2.3.13
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-02-10 00:00:00.000000000Z
12
+ date: 2012-02-23 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: zip
16
- requirement: &11824140 !ruby/object:Gem::Requirement
16
+ requirement: &19776580 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *11824140
24
+ version_requirements: *19776580
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rest-client
27
- requirement: &11823620 !ruby/object:Gem::Requirement
27
+ requirement: &19775720 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *11823620
35
+ version_requirements: *19775720
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: rest
38
- requirement: &11823040 !ruby/object:Gem::Requirement
38
+ requirement: &19775140 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *11823040
46
+ version_requirements: *19775140
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: bundler
49
- requirement: &11822560 !ruby/object:Gem::Requirement
49
+ requirement: &19774600 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *11822560
57
+ version_requirements: *19774600
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: zip
60
- requirement: &11822080 !ruby/object:Gem::Requirement
60
+ requirement: &19774020 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *11822080
68
+ version_requirements: *19774020
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rest-client
71
- requirement: &11821600 !ruby/object:Gem::Requirement
71
+ requirement: &19773440 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *11821600
79
+ version_requirements: *19773440
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: rest
82
- requirement: &11821120 !ruby/object:Gem::Requirement
82
+ requirement: &19772860 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,10 +87,10 @@ dependencies:
87
87
  version: '0'
88
88
  type: :runtime
89
89
  prerelease: false
90
- version_requirements: *11821120
90
+ version_requirements: *19772860
91
91
  - !ruby/object:Gem::Dependency
92
92
  name: bundler
93
- requirement: &11820640 !ruby/object:Gem::Requirement
93
+ requirement: &19772320 !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements:
96
96
  - - ! '>='
@@ -98,7 +98,7 @@ dependencies:
98
98
  version: '0'
99
99
  type: :runtime
100
100
  prerelease: false
101
- version_requirements: *11820640
101
+ version_requirements: *19772320
102
102
  description: The official IronWorker gem for IronWorker by Iron.io. http://www.iron.io
103
103
  email: travis@iron.io
104
104
  executables: []