simple_worker 0.7.3 → 0.7.4
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/railtie.rb +0 -84
- data/lib/simple_worker/base.rb +37 -68
- data/lib/simple_worker/config.rb +174 -6
- data/lib/simple_worker/service.rb +45 -35
- data/lib/simple_worker/utils.rb +11 -0
- data/lib/simple_worker.rb +1 -0
- metadata +4 -3
data/lib/railtie.rb
CHANGED
@@ -6,95 +6,11 @@ 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
10
|
initializer "simple_worker.configure_rails_initialization" do |app|
|
22
|
-
SimpleWorker.logger.info "Initializing SimpleWorker for Rails 3..."
|
23
|
-
start_time = Time.now
|
24
|
-
SimpleWorker.configure do |c2|
|
25
|
-
models_path = File.join(Rails.root, 'app/models/*.rb')
|
26
|
-
c2.models = Dir.glob(models_path)
|
27
|
-
mailers_path = File.join(Rails.root, 'app/mailers/*.rb')
|
28
|
-
c2.mailers = Dir.glob(mailers_path).collect { |m| {:filename=>m, :name => File.basename(m), :path_to_templates=>File.join(Rails.root, "app/views/#{File.basename(m, File.extname(m))}")} }
|
29
|
-
c2.extra_requires += ['active_support/core_ext', 'action_mailer']
|
30
|
-
#puts 'DB FILE=' + File.join(Rails.root, 'config', 'database.yml').to_s
|
31
|
-
if defined?(ActiveRecord) && File.exist?(File.join(Rails.root, 'config', 'database.yml'))
|
32
|
-
c2.extra_requires += ['active_record']
|
33
|
-
c2.database = Rails.configuration.database_configuration[Rails.env]
|
34
|
-
else
|
35
|
-
#puts 'NOT DOING ACTIVERECORD'
|
36
|
-
end
|
37
|
-
c2.gems = get_required_gems if defined?(Bundler)
|
38
|
-
SimpleWorker.logger.debug "MODELS " + c2.models.inspect
|
39
|
-
SimpleWorker.logger.debug "MAILERS " + c2.mailers.inspect
|
40
|
-
SimpleWorker.logger.debug "DATABASE " + c2.database.inspect
|
41
|
-
SimpleWorker.logger.debug "GEMS " + c2.gems.inspect
|
42
|
-
end
|
43
|
-
end_time = Time.now
|
44
|
-
SimpleWorker.logger.info "SimpleWorker initialized. Duration: #{((end_time.to_f-start_time.to_f) * 1000.0).to_i} ms"
|
45
11
|
|
46
12
|
end
|
47
13
|
|
48
|
-
def get_required_gems
|
49
|
-
gems_in_gemfile = Bundler.environment.dependencies.select { |d| d.groups.include?(:default) }
|
50
|
-
SimpleWorker.logger.debug 'gems in gemfile=' + gems_in_gemfile.inspect
|
51
|
-
gems =[]
|
52
|
-
specs = Bundler.load.specs
|
53
|
-
SimpleWorker.logger.debug 'Bundler specs=' + specs.inspect
|
54
|
-
SimpleWorker.logger.debug "gems_to_skip=" + self.class.gems_to_skip.inspect
|
55
|
-
specs.each do |spec|
|
56
|
-
SimpleWorker.logger.debug 'spec.name=' + spec.name.inspect
|
57
|
-
SimpleWorker.logger.debug 'spec=' + spec.inspect
|
58
|
-
if self.class.gems_to_skip.include?(spec.name)
|
59
|
-
SimpleWorker.logger.debug "Skipping #{spec.name}"
|
60
|
-
next
|
61
|
-
end
|
62
|
-
# next if dep.name=='rails' #monkey patch
|
63
|
-
gem_info = {:name=>spec.name, :version=>spec.version}
|
64
|
-
gem_info[:auto_merged] = true
|
65
|
-
# Now find dependency in gemfile in case user set the require
|
66
|
-
dep = gems_in_gemfile.find { |g| g.name == gem_info[:name] }
|
67
|
-
if dep
|
68
|
-
SimpleWorker.logger.debug 'dep found in gemfile: ' + dep.inspect
|
69
|
-
SimpleWorker.logger.debug 'autorequire=' + dep.autorequire.inspect
|
70
|
-
gem_info[:require] = dep.autorequire if dep.autorequire
|
71
|
-
# spec = specs.find { |g| g.name==gem_info[:name] }
|
72
|
-
end
|
73
|
-
gem_info[:version] = spec.version.to_s
|
74
|
-
gems << gem_info
|
75
|
-
path = SimpleWorker::Service.get_gem_path(gem_info)
|
76
|
-
if path
|
77
|
-
gem_info[:path] = path
|
78
|
-
if gem_info[:require].nil? && dep
|
79
|
-
# see if we should try to require this in our worker
|
80
|
-
require_path = gem_info[:path] + "/lib/#{gem_info[:name]}.rb"
|
81
|
-
SimpleWorker.logger.debug "require_path=" + require_path
|
82
|
-
if File.exists?(require_path)
|
83
|
-
SimpleWorker.logger.debug "File exists for require"
|
84
|
-
gem_info[:require] = gem_info[:name]
|
85
|
-
else
|
86
|
-
SimpleWorker.logger.debug "no require"
|
87
|
-
# gem_info[:no_require] = true
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
# else
|
92
|
-
# SimpleWorker.logger.warn "Could not find gem spec for #{gem_info[:name]}"
|
93
|
-
# raise "Could not find gem spec for #{gem_info[:name]}"
|
94
|
-
# end
|
95
|
-
end
|
96
|
-
gems
|
97
|
-
end
|
98
14
|
|
99
15
|
end
|
100
16
|
end
|
data/lib/simple_worker/base.rb
CHANGED
@@ -11,20 +11,20 @@ module SimpleWorker
|
|
11
11
|
attr_accessor :subclass, :caller_file
|
12
12
|
@merged = {}
|
13
13
|
@merged_workers = {}
|
14
|
-
@merged_gems =
|
14
|
+
@merged_gems = {}
|
15
15
|
@merged_mailers = []
|
16
16
|
@merged_folders = {}
|
17
17
|
@unmerged = {}
|
18
|
-
@unmerged_gems =
|
18
|
+
@unmerged_gems = {}
|
19
19
|
|
20
20
|
def reset!
|
21
21
|
@merged = {}
|
22
22
|
@merged_workers = {}
|
23
|
-
@merged_gems =
|
23
|
+
@merged_gems = {}
|
24
24
|
@merged_mailers = []
|
25
25
|
@merged_folders = {}
|
26
26
|
@unmerged = {}
|
27
|
-
@unmerged_gems =
|
27
|
+
@unmerged_gems = {}
|
28
28
|
end
|
29
29
|
|
30
30
|
def inherited(subclass)
|
@@ -44,48 +44,10 @@ module SimpleWorker
|
|
44
44
|
super
|
45
45
|
end
|
46
46
|
|
47
|
-
def check_for_file(f)
|
48
|
-
SimpleWorker.logger.debug 'Checking for ' + f.to_s
|
49
|
-
f = f.to_str
|
50
|
-
unless ends_with?(f, ".rb")
|
51
|
-
f << ".rb"
|
52
|
-
end
|
53
|
-
exists = false
|
54
|
-
if File.exist? f
|
55
|
-
exists = true
|
56
|
-
else
|
57
|
-
# try relative
|
58
|
-
# p caller
|
59
|
-
f2 = File.join(File.dirname(caller[3]), f)
|
60
|
-
puts 'f2=' + f2
|
61
|
-
if File.exist? f2
|
62
|
-
exists = true
|
63
|
-
f = f2
|
64
|
-
end
|
65
|
-
end
|
66
|
-
unless exists
|
67
|
-
raise "File not found: " + f
|
68
|
-
end
|
69
|
-
f = File.expand_path(f)
|
70
|
-
require f
|
71
|
-
f
|
72
|
-
end
|
73
|
-
|
74
47
|
# merges the specified gem.
|
75
48
|
def merge_gem(gem_name, options={})
|
76
|
-
gem_info =
|
77
|
-
|
78
|
-
gem_info.merge!(options)
|
79
|
-
else
|
80
|
-
gem_info[:version] = options
|
81
|
-
end
|
82
|
-
path = SimpleWorker::Service.get_gem_path(gem_info)
|
83
|
-
SimpleWorker.logger.debug "Gem path=#{path}"
|
84
|
-
if !path
|
85
|
-
raise "Gem path not found for #{gem_name}"
|
86
|
-
end
|
87
|
-
gem_info[:path] = path
|
88
|
-
@merged_gems << gem_info
|
49
|
+
gem_info = SimpleWorker::MergeHelper.create_gem_info(gem_name, options)
|
50
|
+
@merged_gems[gem_name.to_s] = gem_info
|
89
51
|
#puts 'before require ' + (options[:require] || gem_name)
|
90
52
|
begin
|
91
53
|
require options[:require] || gem_name
|
@@ -96,13 +58,17 @@ module SimpleWorker
|
|
96
58
|
|
97
59
|
|
98
60
|
def unmerge_gem(gem_name)
|
99
|
-
gem_info = {:name=>gem_name}
|
100
|
-
|
61
|
+
#gem_info = {:name=>gem_name}
|
62
|
+
#@unmerged_gems[gem_name.to_s] = gem_info
|
63
|
+
gs = gem_name.to_s
|
64
|
+
gem_info = {:name=>gs}
|
65
|
+
@unmerged_gems[gs] = gem_info
|
66
|
+
@merged_gems.delete(gs)
|
101
67
|
end
|
102
68
|
|
103
69
|
#merge action_mailer mailers
|
104
70
|
def merge_mailer(mailer, params={})
|
105
|
-
|
71
|
+
f2 = SimpleWorker::MergeHelper.check_for_file mailer, caller[2]
|
106
72
|
basename = File.basename(mailer, File.extname(mailer))
|
107
73
|
path_to_templates = params[:path_to_templates] || File.join(Rails.root, "app/views/#{basename}")
|
108
74
|
@merged_mailers << {:name=>basename, :path_to_templates=>path_to_templates, :filename => mailer}.merge!(params)
|
@@ -136,8 +102,8 @@ module SimpleWorker
|
|
136
102
|
def merge(*files)
|
137
103
|
ret = nil
|
138
104
|
files.each do |f|
|
139
|
-
f2 = check_for_file(f)
|
140
|
-
ret =
|
105
|
+
f2 = SimpleWorker::MergeHelper.check_for_file(f, caller[2])
|
106
|
+
ret = {:name=>f, :path=>f2}
|
141
107
|
@merged[File.basename(f2)] = ret
|
142
108
|
end
|
143
109
|
ret
|
@@ -147,15 +113,11 @@ module SimpleWorker
|
|
147
113
|
# where a lot of things are auto-merged by default like your models.
|
148
114
|
def unmerge(*files)
|
149
115
|
files.each do |f|
|
150
|
-
f2 = check_for_file(f)
|
116
|
+
f2 = SimpleWorker::MergeHelper.check_for_file(f, caller[2])
|
151
117
|
@unmerged[File.basename(f2)] = {:name=>f, :path=>f2}
|
152
118
|
end
|
153
119
|
end
|
154
120
|
|
155
|
-
def ends_with?(s, suffix)
|
156
|
-
suffix = suffix.to_s
|
157
|
-
s[-suffix.length, suffix.length] == suffix
|
158
|
-
end
|
159
121
|
|
160
122
|
# Use this to merge in other workers. These are treated differently the normal merged files because
|
161
123
|
# they will be uploaded separately and treated as distinctly separate workers.
|
@@ -354,12 +316,12 @@ module SimpleWorker
|
|
354
316
|
private
|
355
317
|
|
356
318
|
def gems_to_merge(merged_gems)
|
357
|
-
list_of_gems =
|
319
|
+
list_of_gems = {}
|
358
320
|
if merged_gems && merged_gems.size > 0
|
359
321
|
installed_gems = SimpleWorker.config.get_server_gems
|
360
|
-
merged_gems.
|
322
|
+
merged_gems.each_pair do |k, gem|
|
361
323
|
gem.merge!({:merge=>(!installed_gems.find { |g| g["name"]==gem[:name] && g["version"]==gem[:version] })})
|
362
|
-
list_of_gems
|
324
|
+
list_of_gems[gem[:name]] = gem # don't' need this if (list_of_gems.select { |k,g| g[:name]==gem[:name] }).empty?
|
363
325
|
end
|
364
326
|
SimpleWorker.logger.debug "#{list_of_gems.inspect}"
|
365
327
|
end
|
@@ -382,8 +344,11 @@ module SimpleWorker
|
|
382
344
|
break if superclass.name == SimpleWorker::Base.name
|
383
345
|
super_merged = superclass.instance_variable_get(:@merged)
|
384
346
|
#puts 'merging caller file: ' + superclass.instance_variable_get(:@caller_file).inspect
|
385
|
-
|
386
|
-
|
347
|
+
caller_to_add = superclass.instance_variable_get(:@caller_file)
|
348
|
+
fb = File.basename(caller_to_add)
|
349
|
+
r = {:name=>fb, :path=>f2}
|
350
|
+
super_merged[fb] = r
|
351
|
+
merged.merge!(super_merged)
|
387
352
|
#puts 'merged with superclass=' + merged.inspect
|
388
353
|
end
|
389
354
|
return merged, rfile, subclass
|
@@ -435,19 +400,23 @@ module SimpleWorker
|
|
435
400
|
# puts 'merged1=' + merged.inspect
|
436
401
|
|
437
402
|
merged, rfile, subclass = SimpleWorker::Base.extract_superclasses_merges(self, merged)
|
438
|
-
if SimpleWorker.config.auto_merge
|
403
|
+
#if SimpleWorker.config.auto_merge
|
439
404
|
puts "Auto merge Enabled"
|
440
|
-
|
405
|
+
#if SimpleWorker.config.models
|
406
|
+
# SimpleWorker.config.models.each do |m|
|
407
|
+
# merged[m] = m
|
408
|
+
# end
|
409
|
+
#end
|
441
410
|
merged_mailers += SimpleWorker.config.mailers if SimpleWorker.config.mailers
|
442
|
-
SimpleWorker.config.gems.each do |gem|
|
443
|
-
|
444
|
-
end
|
445
|
-
end
|
446
|
-
unless merged_gems.
|
411
|
+
#SimpleWorker.config.gems.each do |gem|
|
412
|
+
# merged_gems[gem[:name]] = gem
|
413
|
+
#end
|
414
|
+
#end
|
415
|
+
unless merged_gems.size == 0
|
447
416
|
merged_gems = gems_to_merge(merged_gems)
|
448
|
-
merged_gems.uniq!
|
417
|
+
#merged_gems.uniq!
|
449
418
|
end
|
450
|
-
|
419
|
+
#merged.uniq!
|
451
420
|
merged_mailers.uniq!
|
452
421
|
options_for_upload = {:merge=>merged, :unmerge=>unmerged, :merged_gems=>merged_gems, :merged_mailers=>merged_mailers, :merged_folders=>merged_folders}
|
453
422
|
options_for_upload[:name] = options[:name] if options[:name]
|
data/lib/simple_worker/config.rb
CHANGED
@@ -16,16 +16,121 @@ module SimpleWorker
|
|
16
16
|
:global_attributes,
|
17
17
|
:models,
|
18
18
|
:mailers,
|
19
|
-
|
19
|
+
#:gems, # todo: move anything that uses this to merged_gems
|
20
20
|
:database,
|
21
21
|
:extra_requires,
|
22
|
-
|
23
|
-
:server_gems
|
22
|
+
#:auto_merge,
|
23
|
+
:server_gems,
|
24
|
+
:merged,
|
25
|
+
:unmerged,
|
26
|
+
:merged_gems,
|
27
|
+
:unmerged_gems
|
24
28
|
|
25
29
|
|
26
30
|
def initialize
|
27
31
|
@global_attributes = {}
|
28
|
-
@extra_requires
|
32
|
+
@extra_requires = []
|
33
|
+
@merged = {}
|
34
|
+
@unmerged = {}
|
35
|
+
@merged_gems = {}
|
36
|
+
@unmerged_gems = {}
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
@gems_to_skip = ['actionmailer', 'actionpack', 'activemodel', 'activeresource', 'activesupport',
|
42
|
+
'bundler',
|
43
|
+
'mail',
|
44
|
+
'mysql2',
|
45
|
+
'rails',
|
46
|
+
'tzinfo' # HUGE!
|
47
|
+
]
|
48
|
+
|
49
|
+
def self.gems_to_skip
|
50
|
+
@gems_to_skip
|
51
|
+
end
|
52
|
+
|
53
|
+
def auto_merge=(b)
|
54
|
+
if b
|
55
|
+
SimpleWorker.logger.info "Initializing SimpleWorker for Rails 3..."
|
56
|
+
start_time = Time.now
|
57
|
+
SimpleWorker.configure do |c2|
|
58
|
+
models_path = File.join(Rails.root, 'app/models/*.rb')
|
59
|
+
models = Dir.glob(models_path)
|
60
|
+
c2.models = models
|
61
|
+
models.each { |model| c2.merge(model) }
|
62
|
+
mailers_path = File.join(Rails.root, 'app/mailers/*.rb')
|
63
|
+
c2.mailers = Dir.glob(mailers_path).collect { |m| {:filename=>m, :name => File.basename(m), :path_to_templates=>File.join(Rails.root, "app/views/#{File.basename(m, File.extname(m))}")} }
|
64
|
+
c2.extra_requires += ['active_support/core_ext', 'action_mailer']
|
65
|
+
#puts 'DB FILE=' + File.join(Rails.root, 'config', 'database.yml').to_s
|
66
|
+
if defined?(ActiveRecord) && File.exist?(File.join(Rails.root, 'config', 'database.yml'))
|
67
|
+
c2.extra_requires += ['active_record']
|
68
|
+
c2.database = Rails.configuration.database_configuration[Rails.env]
|
69
|
+
else
|
70
|
+
#puts 'NOT DOING ACTIVERECORD'
|
71
|
+
end
|
72
|
+
c2.merged_gems.merge!(get_required_gems) if defined?(Bundler)
|
73
|
+
SimpleWorker.logger.debug "MODELS " + c2.models.inspect
|
74
|
+
SimpleWorker.logger.debug "MAILERS " + c2.mailers.inspect
|
75
|
+
SimpleWorker.logger.debug "DATABASE " + c2.database.inspect
|
76
|
+
#SimpleWorker.logger.debug "GEMS " + c2.gems.inspect
|
77
|
+
end
|
78
|
+
end_time = Time.now
|
79
|
+
SimpleWorker.logger.info "SimpleWorker initialized. Duration: #{((end_time.to_f-start_time.to_f) * 1000.0).to_i} ms"
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
def get_required_gems
|
85
|
+
gems_in_gemfile = Bundler.environment.dependencies.select { |d| d.groups.include?(:default) }
|
86
|
+
SimpleWorker.logger.debug 'gems in gemfile=' + gems_in_gemfile.inspect
|
87
|
+
gems = {}
|
88
|
+
specs = Bundler.load.specs
|
89
|
+
SimpleWorker.logger.debug 'Bundler specs=' + specs.inspect
|
90
|
+
SimpleWorker.logger.debug "gems_to_skip=" + self.class.gems_to_skip.inspect
|
91
|
+
specs.each do |spec|
|
92
|
+
SimpleWorker.logger.debug 'spec.name=' + spec.name.inspect
|
93
|
+
SimpleWorker.logger.debug 'spec=' + spec.inspect
|
94
|
+
if self.class.gems_to_skip.include?(spec.name)
|
95
|
+
SimpleWorker.logger.debug "Skipping #{spec.name}"
|
96
|
+
next
|
97
|
+
end
|
98
|
+
# next if dep.name=='rails' #monkey patch
|
99
|
+
gem_info = {:name=>spec.name, :version=>spec.version}
|
100
|
+
gem_info[:auto_merged] = true
|
101
|
+
gem_info[:merge] = true
|
102
|
+
# Now find dependency in gemfile in case user set the require
|
103
|
+
dep = gems_in_gemfile.find { |g| g.name == gem_info[:name] }
|
104
|
+
if dep
|
105
|
+
SimpleWorker.logger.debug 'dep found in gemfile: ' + dep.inspect
|
106
|
+
SimpleWorker.logger.debug 'autorequire=' + dep.autorequire.inspect
|
107
|
+
gem_info[:require] = dep.autorequire if dep.autorequire
|
108
|
+
# spec = specs.find { |g| g.name==gem_info[:name] }
|
109
|
+
end
|
110
|
+
gem_info[:version] = spec.version.to_s
|
111
|
+
gems[gem_info[:name]] = gem_info
|
112
|
+
path = SimpleWorker::Service.get_gem_path(gem_info)
|
113
|
+
if path
|
114
|
+
gem_info[:path] = path
|
115
|
+
if gem_info[:require].nil? && dep
|
116
|
+
# see if we should try to require this in our worker
|
117
|
+
require_path = gem_info[:path] + "/lib/#{gem_info[:name]}.rb"
|
118
|
+
SimpleWorker.logger.debug "require_path=" + require_path
|
119
|
+
if File.exists?(require_path)
|
120
|
+
SimpleWorker.logger.debug "File exists for require"
|
121
|
+
gem_info[:require] = gem_info[:name]
|
122
|
+
else
|
123
|
+
SimpleWorker.logger.debug "no require"
|
124
|
+
# gem_info[:no_require] = true
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
# else
|
129
|
+
# SimpleWorker.logger.warn "Could not find gem spec for #{gem_info[:name]}"
|
130
|
+
# raise "Could not find gem spec for #{gem_info[:name]}"
|
131
|
+
# end
|
132
|
+
end
|
133
|
+
gems
|
29
134
|
end
|
30
135
|
|
31
136
|
def get_server_gems
|
@@ -43,11 +148,74 @@ module SimpleWorker
|
|
43
148
|
config_data
|
44
149
|
end
|
45
150
|
|
151
|
+
def merge(file)
|
152
|
+
f2 = SimpleWorker::MergeHelper.check_for_file(file, caller[2])
|
153
|
+
ret = {:name=>file, :path=>f2}
|
154
|
+
@merged[File.basename(f2)] = ret
|
155
|
+
end
|
156
|
+
|
157
|
+
# Merge a gem globally here
|
158
|
+
def merge_gem(gem_name, options={})
|
159
|
+
merged_gems[gem_name.to_s] = SimpleWorker::MergeHelper.create_gem_info(gem_name, options)
|
160
|
+
end
|
161
|
+
|
162
|
+
# Unmerge a global gem
|
163
|
+
def unmerge_gem(gem_name)
|
164
|
+
gs = gem_name.to_s
|
165
|
+
gem_info = {:name=>gs}
|
166
|
+
unmerged_gems[gs] = gem_info
|
167
|
+
merged_gems.delete(gs)
|
168
|
+
end
|
169
|
+
|
46
170
|
end
|
47
171
|
|
48
|
-
# Can merge a gem globally here
|
49
|
-
def self.merge_gem(options)
|
50
172
|
|
173
|
+
class MergeHelper
|
174
|
+
|
175
|
+
# callerr is original file that is calling the merge function, ie: your worker.
|
176
|
+
# See Base for examples.
|
177
|
+
def self.check_for_file(f, callerr)
|
178
|
+
SimpleWorker.logger.debug 'Checking for ' + f.to_s
|
179
|
+
f = f.to_str
|
180
|
+
unless Utils.ends_with?(f, ".rb")
|
181
|
+
f << ".rb"
|
182
|
+
end
|
183
|
+
exists = false
|
184
|
+
if File.exist? f
|
185
|
+
exists = true
|
186
|
+
else
|
187
|
+
# try relative
|
188
|
+
# p caller
|
189
|
+
f2 = File.join(File.dirname(callerr), f)
|
190
|
+
puts 'f2=' + f2
|
191
|
+
if File.exist? f2
|
192
|
+
exists = true
|
193
|
+
f = f2
|
194
|
+
end
|
195
|
+
end
|
196
|
+
unless exists
|
197
|
+
raise "File not found: " + f
|
198
|
+
end
|
199
|
+
f = File.expand_path(f)
|
200
|
+
require f
|
201
|
+
f
|
202
|
+
end
|
203
|
+
|
204
|
+
def self.create_gem_info(gem_name, options={})
|
205
|
+
gem_info = {:name=>gem_name, :merge=>true}
|
206
|
+
if options.is_a?(Hash)
|
207
|
+
gem_info.merge!(options)
|
208
|
+
else
|
209
|
+
gem_info[:version] = options
|
210
|
+
end
|
211
|
+
path = SimpleWorker::Service.get_gem_path(gem_info)
|
212
|
+
SimpleWorker.logger.debug "Gem path=#{path}"
|
213
|
+
if !path
|
214
|
+
raise "Gem path not found for #{gem_name}"
|
215
|
+
end
|
216
|
+
gem_info[:path] = path
|
217
|
+
gem_info
|
218
|
+
end
|
51
219
|
end
|
52
220
|
|
53
221
|
end
|
@@ -96,24 +96,31 @@ module SimpleWorker
|
|
96
96
|
end
|
97
97
|
end
|
98
98
|
|
99
|
-
def build_merged_file(filename,
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
merge = merge.nil? ? {} : merge.dup
|
104
|
-
SimpleWorker.logger.debug "merge"
|
99
|
+
def build_merged_file(filename, merged, unmerge, merged_gems, merged_mailers, merged_folders)
|
100
|
+
|
101
|
+
merge = SimpleWorker.config.merged.dup
|
102
|
+
merge.merge!(merged) if merged
|
105
103
|
if unmerge
|
106
104
|
unmerge.each_pair do |x, y|
|
107
105
|
deleted = merge.delete x
|
108
106
|
SimpleWorker.logger.debug "Unmerging #{x}. Success? #{deleted}"
|
109
107
|
end
|
110
108
|
end
|
109
|
+
|
110
|
+
merged_gems = merged_gems.merge(SimpleWorker.config.merged_gems)
|
111
|
+
puts 'merged_gems=' + merged_gems.inspect
|
112
|
+
SimpleWorker.config.unmerged_gems.each_pair do |k, v|
|
113
|
+
puts 'unmerging gem=' + k.inspect
|
114
|
+
merged_gems.delete(k)
|
115
|
+
end
|
116
|
+
puts 'merged_gems_after=' + merged_gems.inspect
|
117
|
+
|
111
118
|
#tmp_file = File.join(Dir.tmpdir(), File.basename(filename))
|
112
119
|
tmp_file = File.join(Dir.tmpdir(), 'runner.rb')
|
113
120
|
File.open(tmp_file, "w") do |f|
|
114
121
|
# add some rails stuff if using Rails
|
115
122
|
|
116
|
-
merge.each_pair do |k,v|
|
123
|
+
merge.each_pair do |k, v|
|
117
124
|
SimpleWorker.logger.debug "merging #{k} into #{filename}"
|
118
125
|
f.write("require_relative '#{k}'\n") # add(File.basename(m), m)
|
119
126
|
end
|
@@ -139,37 +146,39 @@ end
|
|
139
146
|
f.write "require 'action_mailer'\n"
|
140
147
|
f.write "ActionMailer::Base.prepend_view_path('templates')\n"
|
141
148
|
end
|
142
|
-
if SimpleWorker.config.auto_merge
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
149
|
+
#if SimpleWorker.config.auto_merge
|
150
|
+
if SimpleWorker.config.merged_gems
|
151
|
+
SimpleWorker.config.merged_gems.each_pair do |k, gem|
|
152
|
+
puts "Bundling gem #{gem[:name]}..."
|
153
|
+
if gem[:merge]
|
154
|
+
f.write "$LOAD_PATH << File.join(File.dirname(__FILE__), '/gems/#{gem[:name]}/lib')\n"
|
155
|
+
end
|
147
156
|
# unless gem[:no_require]
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
end
|
154
|
-
puts gem[:require].inspect
|
155
|
-
gem[:require].each do |r|
|
156
|
-
puts 'adding require to file ' + r.to_s
|
157
|
-
f.write "require '#{r}'\n"
|
158
|
-
end
|
159
|
-
# end
|
157
|
+
puts 'writing requires: ' + gem[:require].inspect
|
158
|
+
if gem[:require].nil?
|
159
|
+
gem[:require] = []
|
160
|
+
elsif gem[:require].is_a?(String)
|
161
|
+
gem[:require] = [gem[:require]]
|
160
162
|
end
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
f.write "require
|
163
|
+
puts gem[:require].inspect
|
164
|
+
gem[:require].each do |r|
|
165
|
+
puts 'adding require to file ' + r.to_s
|
166
|
+
f.write "require '#{r}'\n"
|
165
167
|
end
|
168
|
+
# end
|
166
169
|
end
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
170
|
+
end
|
171
|
+
if SimpleWorker.config.merged
|
172
|
+
SimpleWorker.config.merged.each_pair do |k, v|
|
173
|
+
f.write "require_relative '#{File.basename(v[:path])}'\n"
|
174
|
+
end
|
175
|
+
end
|
176
|
+
if SimpleWorker.config.mailers
|
177
|
+
SimpleWorker.config.mailers.each do |mailer|
|
178
|
+
f.write "require_relative '#{mailer[:name]}'\n"
|
171
179
|
end
|
172
180
|
end
|
181
|
+
#end
|
173
182
|
#f.write File.open(filename, 'r') { |mo| mo.read }
|
174
183
|
f.write("require_relative '#{File.basename(filename)}'")
|
175
184
|
end
|
@@ -187,7 +196,7 @@ end
|
|
187
196
|
File.delete(fname2) if File.exist?(fname2)
|
188
197
|
Zip::ZipFile.open(fname2, 'w') do |f|
|
189
198
|
if merged_gems && merged_gems.size > 0
|
190
|
-
merged_gems.
|
199
|
+
merged_gems.each_pair do |k, gem|
|
191
200
|
next unless gem[:merge]
|
192
201
|
# puts 'gem=' + gem.inspect
|
193
202
|
path = gem[:path] # get_gem_path(gem)
|
@@ -226,8 +235,9 @@ end
|
|
226
235
|
end
|
227
236
|
end
|
228
237
|
|
229
|
-
merge
|
230
|
-
|
238
|
+
puts "merge=" + merge.inspect
|
239
|
+
merge.each_pair do |k, v|
|
240
|
+
puts "merging k=#{k.inspect} v=#{v.inspect} into #{filename}"
|
231
241
|
f.add(File.basename(v[:path]), v[:path])
|
232
242
|
end
|
233
243
|
if merged_mailers && merged_mailers.size > 0
|
data/lib/simple_worker.rb
CHANGED
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: simple_worker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 0.7.
|
5
|
+
version: 0.7.4
|
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-08-
|
13
|
+
date: 2011-08-03 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: zip
|
@@ -52,6 +52,7 @@ files:
|
|
52
52
|
- lib/simple_worker/runner.rb
|
53
53
|
- lib/simple_worker/service.rb
|
54
54
|
- lib/simple_worker/used_in_worker.rb
|
55
|
+
- lib/simple_worker/utils.rb
|
55
56
|
- rails/init.rb
|
56
57
|
- README.markdown
|
57
58
|
homepage: http://github.com/appoxy/simple_worker
|
@@ -77,7 +78,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
78
|
requirements: []
|
78
79
|
|
79
80
|
rubyforge_project:
|
80
|
-
rubygems_version: 1.8.
|
81
|
+
rubygems_version: 1.8.6
|
81
82
|
signing_key:
|
82
83
|
specification_version: 3
|
83
84
|
summary: The official SimpleWorker gem for http://www.simpleworker.com
|