iron_worker 2.2.0 → 2.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION.yml +1 -1
- data/lib/iron_worker/base.rb +3 -2
- data/lib/iron_worker/config.rb +5 -3
- data/lib/iron_worker/service.rb +56 -34
- metadata +36 -14
data/VERSION.yml
CHANGED
data/lib/iron_worker/base.rb
CHANGED
@@ -214,9 +214,10 @@ module IronWorker
|
|
214
214
|
# running worker, it will be rejected unless you set this explicitly so we know you meant to do it.
|
215
215
|
def queue(options={})
|
216
216
|
# puts 'in queue'
|
217
|
+
|
217
218
|
set_auto_attributes
|
218
219
|
upload_if_needed(options)
|
219
|
-
|
220
|
+
IronWorker.service.config.force_upload = IronWorker.service.config.force_upload && is_local?
|
220
221
|
response = IronWorker.service.queue(self.class.name, sw_get_data, options)
|
221
222
|
IronWorker.service.logger.debug 'queue response=' + response.inspect
|
222
223
|
@response = response
|
@@ -287,7 +288,7 @@ module IronWorker
|
|
287
288
|
|
288
289
|
# Retrieves the log for this worker from the IronWorker service.
|
289
290
|
def get_log(options={})
|
290
|
-
IronWorker.service.
|
291
|
+
IronWorker.service.log(task_id, options)
|
291
292
|
end
|
292
293
|
|
293
294
|
# Callbacks for developer
|
data/lib/iron_worker/config.rb
CHANGED
@@ -28,7 +28,8 @@ module IronWorker
|
|
28
28
|
:unmerged,
|
29
29
|
:merged_gems,
|
30
30
|
:unmerged_gems,
|
31
|
-
:force_upload
|
31
|
+
:force_upload,
|
32
|
+
:beta
|
32
33
|
|
33
34
|
|
34
35
|
def initialize
|
@@ -249,14 +250,15 @@ module IronWorker
|
|
249
250
|
else
|
250
251
|
gem_info[:version] = options
|
251
252
|
end
|
252
|
-
gem_info[:require] ||= gem_name
|
253
253
|
|
254
|
-
path = IronWorker::Service.get_gem_path(gem_info)
|
254
|
+
gemspec, path = IronWorker::Service.get_gem_path(gem_info)
|
255
255
|
IronWorker.logger.debug "Gem path=#{path}"
|
256
256
|
if !path
|
257
257
|
raise "Gem '#{gem_name}' not found."
|
258
258
|
end
|
259
|
+
gem_info[:gemspec] = gemspec
|
259
260
|
gem_info[:path] = path
|
261
|
+
gem_info[:require] ||= gem_name
|
260
262
|
gem_info
|
261
263
|
end
|
262
264
|
end
|
data/lib/iron_worker/service.rb
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
require 'base64'
|
2
2
|
require 'logger'
|
3
3
|
require 'zip'
|
4
|
+
require 'bundler'
|
4
5
|
require 'rest_client'
|
5
6
|
require 'json'
|
6
7
|
|
@@ -47,23 +48,25 @@ module IronWorker
|
|
47
48
|
existing_md5 = IO.read(md5_f)
|
48
49
|
end
|
49
50
|
|
50
|
-
# Check for code changes.
|
51
|
-
md5 = Digest::MD5.hexdigest(File.read(filename))
|
52
|
-
new_code = false
|
53
|
-
if self.config.force_upload || md5 != existing_md5
|
54
|
-
IronWorker.logger.info "Uploading #{class_name}, code modified."
|
55
|
-
File.open(md5_f, 'w') { |f| f.write(md5) }
|
56
|
-
new_code = true
|
57
|
-
# todo: delete md5 file if error occurs during upload process
|
58
|
-
else
|
59
|
-
# puts "#{class_name}: same code, not uploading"
|
60
|
-
return
|
61
|
-
end
|
62
51
|
|
63
52
|
begin
|
64
53
|
|
65
54
|
zip_filename = build_merged_file(filename, options[:merge], options[:unmerge], options[:merged_gems], options[:merged_mailers], options[:merged_folders])
|
66
55
|
|
56
|
+
# Check for code changes.
|
57
|
+
zipfile = Zip::ZipFile.open(zip_filename, Zip::ZipFile::CREATE)
|
58
|
+
crc = zipfile.entries.collect{|x|x.crc}.inject(:+)
|
59
|
+
new_code = false
|
60
|
+
if self.config.force_upload || crc.to_s != existing_md5
|
61
|
+
IronWorker.logger.info "Uploading #{class_name}, code modified."
|
62
|
+
File.open(md5_f, 'w') { |f| f.write(crc) }
|
63
|
+
new_code = true
|
64
|
+
# todo: delete md5 file if error occurs during upload process
|
65
|
+
else
|
66
|
+
# puts "#{class_name}: same code, not uploading"
|
67
|
+
return
|
68
|
+
end
|
69
|
+
|
67
70
|
if new_code
|
68
71
|
upload_code(name, zip_filename, 'runner.rb', :runtime=>'ruby')
|
69
72
|
end
|
@@ -96,10 +99,31 @@ module IronWorker
|
|
96
99
|
gems = gems.select { |g| g.version.version==gem_info[:version] } if gem_info[:version]
|
97
100
|
if !gems.empty?
|
98
101
|
gem = gems.last
|
99
|
-
gem.full_gem_path
|
102
|
+
return gem,gem.full_gem_path
|
100
103
|
else
|
101
|
-
return nil
|
104
|
+
return nil,nil
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
|
109
|
+
def gem_dependencies(list_of_gems)
|
110
|
+
deps = []
|
111
|
+
dependendent_gems ={}
|
112
|
+
list_of_gems.each_value do |v|
|
113
|
+
@deps = v[:gemspec].dependencies
|
114
|
+
@deps.each do |d|
|
115
|
+
deps << Bundler::DepProxy.new(d, 'ruby')
|
116
|
+
end
|
102
117
|
end
|
118
|
+
filtered_deps = deps.select { |d| d.type != :development }
|
119
|
+
index = Bundler::Index.new
|
120
|
+
Gem::Specification.all.collect { |s| index<<s }
|
121
|
+
list = Bundler::Resolver.resolve(filtered_deps, index)
|
122
|
+
list.each do |gemspec|
|
123
|
+
next if list_of_gems.keys.include?(gemspec.name)
|
124
|
+
dependendent_gems[gemspec.name] = IronWorker::MergeHelper.create_gem_info(gemspec.name, gemspec.version.version)
|
125
|
+
end
|
126
|
+
dependendent_gems
|
103
127
|
end
|
104
128
|
|
105
129
|
def build_merged_file(filename, merged, unmerge, merged_gems, merged_mailers, merged_folders)
|
@@ -122,7 +146,8 @@ module IronWorker
|
|
122
146
|
merged_gems.delete(k)
|
123
147
|
end
|
124
148
|
IronWorker.logger.debug 'merged_gems_after=' + merged_gems.inspect
|
125
|
-
|
149
|
+
gems_dependencies = IronWorker.config.beta ? gem_dependencies(merged_gems) : {}
|
150
|
+
IronWorker.logger.debug 'gem_dependencies=' + gems_dependencies.inspect
|
126
151
|
merged_mailers ||= {}
|
127
152
|
merged_mailers = merged_mailers.merge(IronWorker.config.mailers) if IronWorker.config.mailers
|
128
153
|
|
@@ -154,6 +179,11 @@ ARGV.each do |arg|
|
|
154
179
|
end
|
155
180
|
require 'json'
|
156
181
|
")
|
182
|
+
#require gems dependencies
|
183
|
+
gems_dependencies.each_pair do |k, gem|
|
184
|
+
IronWorker.logger.debug "Bundling gem #{gem[:name]}..."
|
185
|
+
f.write "$LOAD_PATH << File.join(File.dirname(__FILE__), '/gems/#{gem[:name]}/lib')\n"
|
186
|
+
end
|
157
187
|
# require merged gems
|
158
188
|
merged_gems.each_pair do |k, gem|
|
159
189
|
IronWorker.logger.debug "Bundling gem #{gem[:name]}..."
|
@@ -263,6 +293,8 @@ end
|
|
263
293
|
# puts 'merged_file_array=' + merge.inspect
|
264
294
|
#File.open(fname2, "w") do |f|
|
265
295
|
File.delete(fname2) if File.exist?(fname2)
|
296
|
+
#merging all gems and deps
|
297
|
+
merged_gems.merge!(gems_dependencies)
|
266
298
|
Zip::ZipFile.open(fname2, 'w') do |f|
|
267
299
|
if merged_gems && merged_gems.size > 0
|
268
300
|
merged_gems.each_pair do |k, gem|
|
@@ -479,41 +511,30 @@ end
|
|
479
511
|
delete(uri, hash_to_send)
|
480
512
|
end
|
481
513
|
|
482
|
-
def get_projects()
|
483
|
-
hash_to_send = {}
|
484
|
-
ret = get("projects", hash_to_send)
|
485
|
-
ret
|
486
|
-
end
|
487
|
-
|
488
514
|
def get_project_id(options={})
|
489
515
|
options[:project_id] || config.project_id
|
490
516
|
end
|
491
517
|
|
492
|
-
def
|
493
|
-
hash_to_send = {}
|
494
|
-
|
495
|
-
ret = get("projects/"+ get_project_id(options) +"/", hash_to_send)
|
496
|
-
#uri = project_url_prefix(id)
|
497
|
-
#puts "get_project, uri = " + uri
|
498
|
-
#ret = get(uri, hash_to_send)
|
499
|
-
ret
|
500
|
-
end
|
501
|
-
|
502
|
-
def get_codes(options={})
|
518
|
+
def codes(options={})
|
503
519
|
hash_to_send = {}
|
504
520
|
uri = "projects/" + get_project_id(options) + "/codes"
|
505
521
|
ret = get(uri, hash_to_send)
|
506
522
|
ret
|
507
523
|
end
|
508
524
|
|
509
|
-
def
|
525
|
+
def schedules(options={})
|
510
526
|
hash_to_send = {}
|
511
527
|
uri = "projects/" + get_project_id(options) + "/schedules"
|
512
528
|
ret = get(uri, hash_to_send)
|
513
529
|
ret
|
514
530
|
end
|
515
531
|
|
516
|
-
def
|
532
|
+
def jobs(options={})
|
533
|
+
puts 'Service.jobs is deprecated, use Service.tasks instead'
|
534
|
+
tasks(options)
|
535
|
+
end
|
536
|
+
|
537
|
+
def tasks(options={})
|
517
538
|
hash_to_send = {}
|
518
539
|
uri = "projects/" + get_project_id(options) + "/tasks"
|
519
540
|
ret = get(uri, hash_to_send)
|
@@ -521,6 +542,7 @@ end
|
|
521
542
|
end
|
522
543
|
|
523
544
|
def get_log(job_id, options={})
|
545
|
+
puts 'Service.get_log is deprecated, use Service.log instead'
|
524
546
|
log(job_id, options)
|
525
547
|
end
|
526
548
|
|
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.
|
4
|
+
version: 2.3.0
|
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:
|
12
|
+
date: 2012-01-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: zip
|
16
|
-
requirement: &
|
16
|
+
requirement: &24684180 !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: *
|
24
|
+
version_requirements: *24684180
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rest-client
|
27
|
-
requirement: &
|
27
|
+
requirement: &24682880 !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: *
|
35
|
+
version_requirements: *24682880
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: rest
|
38
|
-
requirement: &
|
38
|
+
requirement: &24681840 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,21 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *24681840
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: bundler
|
49
|
+
requirement: &24681260 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *24681260
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: zip
|
49
|
-
requirement: &
|
60
|
+
requirement: &24680760 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :runtime
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *24680760
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: rest-client
|
60
|
-
requirement: &
|
71
|
+
requirement: &24680260 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - ! '>='
|
@@ -65,10 +76,21 @@ dependencies:
|
|
65
76
|
version: '0'
|
66
77
|
type: :runtime
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *24680260
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: rest
|
71
|
-
requirement: &
|
82
|
+
requirement: &24679760 !ruby/object:Gem::Requirement
|
83
|
+
none: false
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
type: :runtime
|
89
|
+
prerelease: false
|
90
|
+
version_requirements: *24679760
|
91
|
+
- !ruby/object:Gem::Dependency
|
92
|
+
name: bundler
|
93
|
+
requirement: &24762060 !ruby/object:Gem::Requirement
|
72
94
|
none: false
|
73
95
|
requirements:
|
74
96
|
- - ! '>='
|
@@ -76,7 +98,7 @@ dependencies:
|
|
76
98
|
version: '0'
|
77
99
|
type: :runtime
|
78
100
|
prerelease: false
|
79
|
-
version_requirements: *
|
101
|
+
version_requirements: *24762060
|
80
102
|
description: The official IronWorker gem for IronWorker by Iron.io. http://www.iron.io
|
81
103
|
email: travis@iron.io
|
82
104
|
executables: []
|