simple_worker 1.0.2 → 1.0.3.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +3 -0
- data/lib/simple_worker/base.rb +7 -8
- data/lib/simple_worker/config.rb +19 -8
- data/lib/simple_worker/service.rb +49 -29
- metadata +5 -5
data/README.markdown
CHANGED
@@ -270,6 +270,9 @@ This allows you to use any gem you'd like with SimpleWorker. This uses the same
|
|
270
270
|
merge_gem "some_gem_with_version", "1.2.3"
|
271
271
|
# or if gem has poor naming scheme
|
272
272
|
merge_gem 'mongoid_i18n', :require => 'mongoid/i18n'
|
273
|
+
# of if gem requires other directories outside lib
|
274
|
+
merge_gem 'prawn', :include_dirs=>['data']
|
275
|
+
|
273
276
|
|
274
277
|
[Check here for more info on merge_gem](http://support.simpleworker.com/kb/working-with-simpleworker/merging-gems-into-your-worker).
|
275
278
|
|
data/lib/simple_worker/base.rb
CHANGED
@@ -43,7 +43,7 @@ module SimpleWorker
|
|
43
43
|
@merged_gems[gem_name.to_s] = gem_info
|
44
44
|
#puts 'before require ' + (options[:require] || gem_name)
|
45
45
|
begin
|
46
|
-
require
|
46
|
+
require gem_info[:require]
|
47
47
|
rescue LoadError=>ex
|
48
48
|
raise "Gem #{gem_name} was found, but we could not load the file '#{options[:require] || gem_name}.rb'. You may need to use :require=>x.........."
|
49
49
|
end
|
@@ -61,8 +61,8 @@ module SimpleWorker
|
|
61
61
|
|
62
62
|
#merge action_mailer mailers
|
63
63
|
def merge_mailer(mailer, params={})
|
64
|
-
f2 = SimpleWorker::MergeHelper.check_for_file
|
65
|
-
basename = File.basename(mailer,
|
64
|
+
f2 = SimpleWorker::MergeHelper.check_for_file(mailer, @caller_file)
|
65
|
+
basename = File.basename(mailer, f2[:extname])
|
66
66
|
path_to_templates = params[:path_to_templates] || File.join(Rails.root, "app/views/#{basename}")
|
67
67
|
@merged_mailers[basename] = {:name=>basename, :path_to_templates=>path_to_templates, :filename => mailer}.merge!(params)
|
68
68
|
end
|
@@ -93,10 +93,9 @@ module SimpleWorker
|
|
93
93
|
#
|
94
94
|
# Example: merge 'models/my_model'
|
95
95
|
def merge(f)
|
96
|
-
ret = nil
|
97
96
|
f2 = SimpleWorker::MergeHelper.check_for_file(f, @caller_file)
|
98
|
-
fbase =
|
99
|
-
ret =
|
97
|
+
fbase = f2[:basename]
|
98
|
+
ret = f2
|
100
99
|
@merged[fbase] = ret
|
101
100
|
ret
|
102
101
|
end
|
@@ -105,8 +104,8 @@ module SimpleWorker
|
|
105
104
|
# where a lot of things are auto-merged by default like your models.
|
106
105
|
def unmerge(f)
|
107
106
|
f2 = SimpleWorker::MergeHelper.check_for_file(f, @caller_file)
|
108
|
-
fbase =
|
109
|
-
@unmerged[fbase] =
|
107
|
+
fbase = f2[:basename]
|
108
|
+
@unmerged[fbase] = f2
|
110
109
|
@merged.delete(fbase)
|
111
110
|
end
|
112
111
|
|
data/lib/simple_worker/config.rb
CHANGED
@@ -153,16 +153,16 @@ module SimpleWorker
|
|
153
153
|
|
154
154
|
def merge(file)
|
155
155
|
f2 = SimpleWorker::MergeHelper.check_for_file(file, caller[2])
|
156
|
-
fbase =
|
157
|
-
ret =
|
156
|
+
fbase = f2[:basename]
|
157
|
+
ret = f2
|
158
158
|
@merged[fbase] = ret
|
159
159
|
ret
|
160
160
|
end
|
161
161
|
|
162
162
|
def unmerge(file)
|
163
163
|
f2 = SimpleWorker::MergeHelper.check_for_file(file, caller[2])
|
164
|
-
fbase =
|
165
|
-
@unmerged[fbase] =
|
164
|
+
fbase = f2[:basename]
|
165
|
+
@unmerged[fbase] =f2
|
166
166
|
@merged.delete(fbase)
|
167
167
|
end
|
168
168
|
|
@@ -189,8 +189,10 @@ module SimpleWorker
|
|
189
189
|
def self.check_for_file(f, callerr)
|
190
190
|
SimpleWorker.logger.debug 'Checking for ' + f.to_s
|
191
191
|
f = f.to_str
|
192
|
-
|
193
|
-
|
192
|
+
f_ext = File.extname(f)
|
193
|
+
if f_ext.empty?
|
194
|
+
f_ext = ".rb"
|
195
|
+
f << f_ext
|
194
196
|
end
|
195
197
|
exists = false
|
196
198
|
if File.exist? f
|
@@ -209,8 +211,13 @@ module SimpleWorker
|
|
209
211
|
raise "File not found: " + f
|
210
212
|
end
|
211
213
|
f = File.expand_path(f)
|
212
|
-
require f
|
213
|
-
|
214
|
+
require f if f_ext == '.rb'
|
215
|
+
ret = {}
|
216
|
+
ret[:path] = f
|
217
|
+
ret[:extname] = f_ext
|
218
|
+
ret[:basename] = File.basename(f)
|
219
|
+
ret[:name] = ret[:basename]
|
220
|
+
ret
|
214
221
|
end
|
215
222
|
|
216
223
|
def self.create_gem_info(gem_name, options={})
|
@@ -220,6 +227,10 @@ module SimpleWorker
|
|
220
227
|
else
|
221
228
|
gem_info[:version] = options
|
222
229
|
end
|
230
|
+
gem_info[:require] ||= gem_name
|
231
|
+
if options[:include_dirs]
|
232
|
+
gem_info[:include_dirs] = options[:include_dirs].is_a?(Array) ? options[:include_dirs] : [options[:include_dirs]]
|
233
|
+
end
|
223
234
|
path = SimpleWorker::Service.get_gem_path(gem_info)
|
224
235
|
SimpleWorker.logger.debug "Gem path=#{path}"
|
225
236
|
if !path
|
@@ -36,16 +36,16 @@ module SimpleWorker
|
|
36
36
|
tmp = Dir.tmpdir()
|
37
37
|
md5file = "simple_worker_#{class_name.gsub("::", ".")}_#{access_key[0, 8]}.md5"
|
38
38
|
existing_md5 = nil
|
39
|
-
|
40
|
-
if File.exists?(
|
41
|
-
existing_md5 = IO.read(
|
39
|
+
md5_f = File.join(tmp, md5file)
|
40
|
+
if File.exists?(md5_f)
|
41
|
+
existing_md5 = IO.read(md5_f)
|
42
42
|
end
|
43
43
|
# Check for code changes.
|
44
44
|
md5 = Digest::MD5.hexdigest(File.read(filename))
|
45
45
|
new_code = false
|
46
46
|
if md5 != existing_md5
|
47
47
|
SimpleWorker.logger.info "Uploading #{class_name}, code modified."
|
48
|
-
File.open(
|
48
|
+
File.open(md5_f, 'w') { |f| f.write(md5) }
|
49
49
|
new_code = true
|
50
50
|
# todo: delete md5 file if error occurs during upload process
|
51
51
|
else
|
@@ -53,21 +53,29 @@ module SimpleWorker
|
|
53
53
|
return
|
54
54
|
end
|
55
55
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
56
|
+
begin
|
57
|
+
|
58
|
+
zip_filename = build_merged_file(filename, options[:merge], options[:unmerge], options[:merged_gems], options[:merged_mailers], options[:merged_folders])
|
59
|
+
SimpleWorker.logger.info 'file size to upload: ' + File.size(zip_filename).to_s
|
60
|
+
|
61
|
+
if new_code
|
62
|
+
options = {
|
63
|
+
"class_name"=>class_name,
|
64
|
+
"name"=>name,
|
65
|
+
"standalone"=>true,
|
66
|
+
"file_name"=> "runner.rb" # File.basename(filename)
|
67
|
+
}
|
68
|
+
#puts 'options for upload=' + options.inspect
|
69
|
+
SimpleWorker.logger.info "Uploading now..."
|
70
|
+
ret = post_file("code/put", File.new(zip_filename), options)
|
71
|
+
SimpleWorker.logger.info "Done uploading."
|
72
|
+
return ret
|
73
|
+
end
|
74
|
+
|
75
|
+
rescue => ex
|
76
|
+
# if it errors, let's delete md5 since it wouldn't have uploaded.
|
77
|
+
File.delete(md5_f)
|
78
|
+
raise ex
|
71
79
|
end
|
72
80
|
end
|
73
81
|
|
@@ -107,14 +115,16 @@ module SimpleWorker
|
|
107
115
|
SimpleWorker.logger.debug "Unmerging #{x}. Success? #{deleted}"
|
108
116
|
end
|
109
117
|
end
|
118
|
+
merged = merge
|
119
|
+
SimpleWorker.logger.debug 'merged=' + merged.inspect
|
110
120
|
|
111
121
|
merged_gems = merged_gems.merge(SimpleWorker.config.merged_gems)
|
112
|
-
|
122
|
+
SimpleWorker.logger.debug 'merged_gems=' + merged_gems.inspect
|
113
123
|
SimpleWorker.config.unmerged_gems.each_pair do |k, v|
|
114
|
-
|
124
|
+
SimpleWorker.logger.debug 'unmerging gem=' + k.inspect
|
115
125
|
merged_gems.delete(k)
|
116
126
|
end
|
117
|
-
|
127
|
+
SimpleWorker.logger.debug 'merged_gems_after=' + merged_gems.inspect
|
118
128
|
|
119
129
|
merged_mailers ||= {}
|
120
130
|
merged_mailers = merged_mailers.merge(SimpleWorker.config.mailers) if SimpleWorker.config.mailers
|
@@ -145,12 +155,12 @@ end
|
|
145
155
|
end
|
146
156
|
#if SimpleWorker.config.auto_merge
|
147
157
|
merged_gems.each_pair do |k, gem|
|
148
|
-
|
158
|
+
SimpleWorker.logger.info "Bundling gem #{gem[:name]}..."
|
149
159
|
if gem[:merge]
|
150
160
|
f.write "$LOAD_PATH << File.join(File.dirname(__FILE__), '/gems/#{gem[:name]}/lib')\n"
|
151
161
|
end
|
152
162
|
# unless gem[:no_require]
|
153
|
-
|
163
|
+
SimpleWorker.logger.debug 'writing requires: ' + gem[:require].inspect
|
154
164
|
if gem[:require].nil?
|
155
165
|
gem[:require] = []
|
156
166
|
elsif gem[:require].is_a?(String)
|
@@ -158,7 +168,7 @@ end
|
|
158
168
|
end
|
159
169
|
puts gem[:require].inspect
|
160
170
|
gem[:require].each do |r|
|
161
|
-
|
171
|
+
SimpleWorker.logger.debug 'adding require to file ' + r.to_s
|
162
172
|
f.write "require '#{r}'\n"
|
163
173
|
end
|
164
174
|
# end
|
@@ -177,7 +187,9 @@ end
|
|
177
187
|
end
|
178
188
|
|
179
189
|
merged.each_pair do |k, v|
|
180
|
-
|
190
|
+
if v[:extname] == ".rb"
|
191
|
+
f.write "require_relative '#{File.basename(v[:path])}'\n"
|
192
|
+
end
|
181
193
|
end
|
182
194
|
merged_mailers.each_pair do |k, mailer|
|
183
195
|
f.write "require_relative '#{mailer[:name]}'\n"
|
@@ -214,7 +226,15 @@ end
|
|
214
226
|
path = gem[:path] # get_gem_path(gem)
|
215
227
|
if path
|
216
228
|
SimpleWorker.logger.debug "Collecting gem #{path}"
|
217
|
-
|
229
|
+
paths_to_use = ["#{path}/*", "#{path}/lib/**/**"]
|
230
|
+
if gem[:include_dirs]
|
231
|
+
SimpleWorker.logger.debug "including extra dirs: " + gem[:include_dirs].inspect
|
232
|
+
gem[:include_dirs].each do |dir|
|
233
|
+
paths_to_use << "#{path}/#{dir}/**/**"
|
234
|
+
end
|
235
|
+
end
|
236
|
+
SimpleWorker.logger.debug 'paths_to_use: ' + paths_to_use.inspect
|
237
|
+
Dir.glob(paths_to_use).each do |file|
|
218
238
|
# todo: could check if directory and it not lib, skip it
|
219
239
|
SimpleWorker.logger.debug 'file for gem=' + file.inspect
|
220
240
|
# puts 'gem2=' + gem.inspect
|
@@ -247,9 +267,9 @@ end
|
|
247
267
|
end
|
248
268
|
end
|
249
269
|
|
250
|
-
|
270
|
+
SimpleWorker.logger.debug "merge=" + merge.inspect
|
251
271
|
merge.each_pair do |k, v|
|
252
|
-
|
272
|
+
SimpleWorker.logger.debug "merging k=#{k.inspect} v=#{v.inspect} into #{filename}"
|
253
273
|
f.add(File.basename(v[:path]), v[:path])
|
254
274
|
end
|
255
275
|
if merged_mailers && merged_mailers.size > 0
|
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:
|
5
|
-
version: 1.0.
|
4
|
+
prerelease: 6
|
5
|
+
version: 1.0.3.beta
|
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-17 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: zip
|
@@ -73,9 +73,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
73
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
74
|
none: false
|
75
75
|
requirements:
|
76
|
-
- - "
|
76
|
+
- - ">"
|
77
77
|
- !ruby/object:Gem::Version
|
78
|
-
version:
|
78
|
+
version: 1.3.1
|
79
79
|
requirements: []
|
80
80
|
|
81
81
|
rubyforge_project:
|