simple_worker 0.7.4 → 1.0.0.beta
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +20 -0
- data/lib/simple_worker/base.rb +29 -37
- data/lib/simple_worker/config.rb +14 -3
- data/lib/simple_worker/server/overrides.rb +204 -0
- data/lib/simple_worker/server/runner.rb +96 -0
- data/lib/simple_worker/service.rb +58 -35
- metadata +7 -6
- data/lib/simple_worker/runner.rb +0 -1
data/README.markdown
CHANGED
@@ -1,3 +1,12 @@
|
|
1
|
+
KNOWN ISSUES IN NEW VERSION
|
2
|
+
=====
|
3
|
+
|
4
|
+
- Cancel chain will not work because we don't have parent task it. Do we need it though?
|
5
|
+
We could just allow kill all by class name and that would be sufficient? (see runner.rb add_sw_params)
|
6
|
+
|
7
|
+
|
8
|
+
|
9
|
+
|
1
10
|
Getting Started
|
2
11
|
===============
|
3
12
|
|
@@ -252,6 +261,17 @@ uploaded separately and treated as distinctly separate workers.
|
|
252
261
|
|
253
262
|
merge_worker "./other_worker.rb", "OtherWorker"
|
254
263
|
|
264
|
+
Merging Mailers
|
265
|
+
---------------------
|
266
|
+
|
267
|
+
You could easily merge mailers you're using in your application.
|
268
|
+
|
269
|
+
merge_mailer 'mailer_file' #if your mailer's templates are placed in default path
|
270
|
+
#or
|
271
|
+
merge_mailer 'mailer_file', {:path_to_templates=>"templates_path"}#if you're using mailer outside of rails with custom templates path
|
272
|
+
|
273
|
+
if you already set auto_merge=true all your mailers already merged.
|
274
|
+
|
255
275
|
Merging Gems
|
256
276
|
---------------------
|
257
277
|
|
data/lib/simple_worker/base.rb
CHANGED
@@ -12,7 +12,7 @@ module SimpleWorker
|
|
12
12
|
@merged = {}
|
13
13
|
@merged_workers = {}
|
14
14
|
@merged_gems = {}
|
15
|
-
@merged_mailers =
|
15
|
+
@merged_mailers = {}
|
16
16
|
@merged_folders = {}
|
17
17
|
@unmerged = {}
|
18
18
|
@unmerged_gems = {}
|
@@ -21,7 +21,7 @@ module SimpleWorker
|
|
21
21
|
@merged = {}
|
22
22
|
@merged_workers = {}
|
23
23
|
@merged_gems = {}
|
24
|
-
@merged_mailers =
|
24
|
+
@merged_mailers = {}
|
25
25
|
@merged_folders = {}
|
26
26
|
@unmerged = {}
|
27
27
|
@unmerged_gems = {}
|
@@ -30,15 +30,8 @@ module SimpleWorker
|
|
30
30
|
def inherited(subclass)
|
31
31
|
subclass.reset!
|
32
32
|
|
33
|
-
# puts "subclass.inspect=" + subclass.inspect
|
34
|
-
# puts 'existing caller=' + (subclass.instance_variable_defined?(:@caller_file) ? subclass.instance_variable_get(:@caller_file).inspect : "nil")
|
35
|
-
# puts "caller=" + caller.inspect
|
36
|
-
# splits = caller[0].split(":")
|
37
|
-
# caller_file = splits[0] + ":" + splits[1]
|
38
33
|
caller_file = caller[0][0...(caller[0].index(":in"))]
|
39
34
|
caller_file = caller_file[0...(caller_file.rindex(":"))]
|
40
|
-
# puts 'caller_file=' + caller_file
|
41
|
-
# don't need these class_variables anymore probably
|
42
35
|
subclass.instance_variable_set(:@caller_file, caller_file)
|
43
36
|
|
44
37
|
super
|
@@ -60,7 +53,7 @@ module SimpleWorker
|
|
60
53
|
def unmerge_gem(gem_name)
|
61
54
|
#gem_info = {:name=>gem_name}
|
62
55
|
#@unmerged_gems[gem_name.to_s] = gem_info
|
63
|
-
|
56
|
+
gs = gem_name.to_s
|
64
57
|
gem_info = {:name=>gs}
|
65
58
|
@unmerged_gems[gs] = gem_info
|
66
59
|
@merged_gems.delete(gs)
|
@@ -68,10 +61,10 @@ module SimpleWorker
|
|
68
61
|
|
69
62
|
#merge action_mailer mailers
|
70
63
|
def merge_mailer(mailer, params={})
|
71
|
-
|
64
|
+
f2 = SimpleWorker::MergeHelper.check_for_file mailer, caller[2]
|
72
65
|
basename = File.basename(mailer, File.extname(mailer))
|
73
66
|
path_to_templates = params[:path_to_templates] || File.join(Rails.root, "app/views/#{basename}")
|
74
|
-
@merged_mailers
|
67
|
+
@merged_mailers[basename] = {:name=>basename, :path_to_templates=>path_to_templates, :filename => mailer}.merge!(params)
|
75
68
|
end
|
76
69
|
|
77
70
|
def merge_folder(path)
|
@@ -99,23 +92,22 @@ module SimpleWorker
|
|
99
92
|
# merges the specified file.
|
100
93
|
#
|
101
94
|
# Example: merge 'models/my_model'
|
102
|
-
def merge(
|
95
|
+
def merge(f)
|
103
96
|
ret = nil
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
end
|
97
|
+
f2 = SimpleWorker::MergeHelper.check_for_file(f, caller[2])
|
98
|
+
fbase = File.basename(f2)
|
99
|
+
ret = {:name=>fbase, :path=>f2}
|
100
|
+
@merged[fbase] = ret
|
109
101
|
ret
|
110
102
|
end
|
111
103
|
|
112
104
|
# Opposite of merge, this will omit the files you specify from being merged in. Useful in Rails apps
|
113
105
|
# where a lot of things are auto-merged by default like your models.
|
114
|
-
def unmerge(
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
106
|
+
def unmerge(f)
|
107
|
+
f2 = SimpleWorker::MergeHelper.check_for_file(f, caller[2])
|
108
|
+
fbase = File.basename(f2)
|
109
|
+
@unmerged[fbase] = {:name=>fbase, :path=>f2}
|
110
|
+
@merged.delete(fbase)
|
119
111
|
end
|
120
112
|
|
121
113
|
|
@@ -346,7 +338,7 @@ module SimpleWorker
|
|
346
338
|
#puts 'merging caller file: ' + superclass.instance_variable_get(:@caller_file).inspect
|
347
339
|
caller_to_add = superclass.instance_variable_get(:@caller_file)
|
348
340
|
fb = File.basename(caller_to_add)
|
349
|
-
r = {:name=>fb, :path=>
|
341
|
+
r = {:name=>fb, :path=>caller_to_add}
|
350
342
|
super_merged[fb] = r
|
351
343
|
merged.merge!(super_merged)
|
352
344
|
#puts 'merged with superclass=' + merged.inspect
|
@@ -400,24 +392,24 @@ module SimpleWorker
|
|
400
392
|
# puts 'merged1=' + merged.inspect
|
401
393
|
|
402
394
|
merged, rfile, subclass = SimpleWorker::Base.extract_superclasses_merges(self, merged)
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
395
|
+
#if SimpleWorker.config.auto_merge
|
396
|
+
puts "Auto merge Enabled"
|
397
|
+
#if SimpleWorker.config.models
|
398
|
+
# SimpleWorker.config.models.each do |m|
|
399
|
+
# merged[m] = m
|
400
|
+
# end
|
401
|
+
#end
|
402
|
+
merged_mailers = merged_mailers.merge(SimpleWorker.config.mailers) if SimpleWorker.config.mailers
|
403
|
+
#SimpleWorker.config.gems.each do |gem|
|
404
|
+
# merged_gems[gem[:name]] = gem
|
405
|
+
#end
|
406
|
+
#end
|
415
407
|
unless merged_gems.size == 0
|
416
408
|
merged_gems = gems_to_merge(merged_gems)
|
417
409
|
#merged_gems.uniq!
|
418
410
|
end
|
419
411
|
#merged.uniq!
|
420
|
-
merged_mailers.uniq!
|
412
|
+
# merged_mailers.uniq!
|
421
413
|
options_for_upload = {:merge=>merged, :unmerge=>unmerged, :merged_gems=>merged_gems, :merged_mailers=>merged_mailers, :merged_folders=>merged_folders}
|
422
414
|
options_for_upload[:name] = options[:name] if options[:name]
|
423
415
|
SimpleWorker.service.upload(rfile, subclass.name, options_for_upload)
|
data/lib/simple_worker/config.rb
CHANGED
@@ -60,7 +60,7 @@ module SimpleWorker
|
|
60
60
|
c2.models = models
|
61
61
|
models.each { |model| c2.merge(model) }
|
62
62
|
mailers_path = File.join(Rails.root, 'app/mailers/*.rb')
|
63
|
-
|
63
|
+
Dir.glob(mailers_path).collect { |m| c2.mailers[File.basename(m)] = {:filename=>m, :name => File.basename(m), :path_to_templates=>File.join(Rails.root, "app/views/#{File.basename(m, File.extname(m))}")} }
|
64
64
|
c2.extra_requires += ['active_support/core_ext', 'action_mailer']
|
65
65
|
#puts 'DB FILE=' + File.join(Rails.root, 'config', 'database.yml').to_s
|
66
66
|
if defined?(ActiveRecord) && File.exist?(File.join(Rails.root, 'config', 'database.yml'))
|
@@ -142,6 +142,8 @@ module SimpleWorker
|
|
142
142
|
|
143
143
|
def get_atts_to_send
|
144
144
|
config_data = {}
|
145
|
+
config_data['access_key'] = access_key
|
146
|
+
config_data['secret_key'] = secret_key
|
145
147
|
config_data['database'] = self.database if self.database
|
146
148
|
config_data['global_attributes'] = self.global_attributes if self.global_attributes
|
147
149
|
config_data['host'] = self.host if self.host
|
@@ -150,8 +152,17 @@ module SimpleWorker
|
|
150
152
|
|
151
153
|
def merge(file)
|
152
154
|
f2 = SimpleWorker::MergeHelper.check_for_file(file, caller[2])
|
153
|
-
|
154
|
-
|
155
|
+
fbase = File.basename(f2)
|
156
|
+
ret = {:name=>fbase, :path=>f2}
|
157
|
+
@merged[fbase] = ret
|
158
|
+
ret
|
159
|
+
end
|
160
|
+
|
161
|
+
def unmerge(file)
|
162
|
+
f2 = SimpleWorker::MergeHelper.check_for_file(file, caller[2])
|
163
|
+
fbase = File.basename(f2)
|
164
|
+
@unmerged[fbase] = {:name=>fbase, :path=>f2}
|
165
|
+
@merged.delete(fbase)
|
155
166
|
end
|
156
167
|
|
157
168
|
# Merge a gem globally here
|
@@ -0,0 +1,204 @@
|
|
1
|
+
|
2
|
+
# This is used when a bad worker is uploaded.
|
3
|
+
class InvalidWorkerError < StandardError
|
4
|
+
|
5
|
+
end
|
6
|
+
|
7
|
+
|
8
|
+
module SimpleWorker
|
9
|
+
|
10
|
+
class << self
|
11
|
+
def running_class=(rc)
|
12
|
+
@@running_class = rc
|
13
|
+
end
|
14
|
+
def running_class
|
15
|
+
@@running_class
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.disable_queueing()
|
20
|
+
@@queueing_enabled = false
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.enable_queueing()
|
24
|
+
@@queueing_enabled = true
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.queueing_enabled?
|
28
|
+
@@queueing_enabled
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
class Base
|
33
|
+
|
34
|
+
class << self
|
35
|
+
|
36
|
+
def merge(*files)
|
37
|
+
#files.each do |file|
|
38
|
+
# file = file.to_s
|
39
|
+
# unless file.end_with?(".rb")
|
40
|
+
# file << ".rb"
|
41
|
+
# end
|
42
|
+
# #puts 'code_dir=' + code_dir.inspect
|
43
|
+
# filename = File.join(code_dir, File.basename(file))
|
44
|
+
# #puts "merge #{filename}"
|
45
|
+
# #puts "FILENAME #{filename}"
|
46
|
+
# require filename if File.exist?(filename) # for backwards compatability
|
47
|
+
#end
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
def merge_folder(path)
|
53
|
+
#puts "PATH=#{path}"
|
54
|
+
#puts "#{code_dir}/#{Digest::MD5.hexdigest(path)}/**/*.rb"
|
55
|
+
#Dir["#{code_dir}/#{Digest::MD5.hexdigest(path)}/**/*.rb"].each do |f|
|
56
|
+
# puts "requiring #{f.inspect}"
|
57
|
+
# require f if File.exist?(f)
|
58
|
+
#end
|
59
|
+
end
|
60
|
+
|
61
|
+
def unmerge(*files)
|
62
|
+
# ignore this here
|
63
|
+
end
|
64
|
+
|
65
|
+
def merge_mailer(mailer, params=nil)
|
66
|
+
#merge(mailer)
|
67
|
+
end
|
68
|
+
|
69
|
+
def merge_gem(gem, version=nil)
|
70
|
+
#gem_info = {:name=>gem}
|
71
|
+
#if version.is_a?(Hash)
|
72
|
+
# gem_info.merge!(version)
|
73
|
+
#else
|
74
|
+
# gem_info[:version] = version
|
75
|
+
#end
|
76
|
+
#gem_name =(gem.match(/^[a-zA-Z0-9\-_]+/)[0])
|
77
|
+
#$LOAD_PATH << File.join(code_dir, "/gems/#{gem_name}") #backwards compatibility, should be removed later
|
78
|
+
#$LOAD_PATH << File.join(code_dir, "/gems/#{gem_name}/lib")
|
79
|
+
# # what's the diff here? This one seems more common: $:.unshift File.join(File.dirname(__FILE__), "/gems/#{gem_name}")
|
80
|
+
# #puts 'gem_info = ' + gem_info.inspect
|
81
|
+
#require gem_info[:require] || gem_name
|
82
|
+
end
|
83
|
+
|
84
|
+
def merge_worker(file, class_name)
|
85
|
+
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
|
90
|
+
def is_remote?
|
91
|
+
true
|
92
|
+
end
|
93
|
+
|
94
|
+
#:todo remove this method later, when new simple_worker gem will be released
|
95
|
+
def is_local?
|
96
|
+
!is_remote?
|
97
|
+
end
|
98
|
+
|
99
|
+
def log(str)
|
100
|
+
puts str.to_s
|
101
|
+
end
|
102
|
+
|
103
|
+
def set_progress(hash)
|
104
|
+
SimpleWorker.service.set_progress(@job_data["task_id"], hash)
|
105
|
+
end
|
106
|
+
|
107
|
+
def something
|
108
|
+
puts 'which class? ' + self.class.name
|
109
|
+
end
|
110
|
+
|
111
|
+
def user_dir
|
112
|
+
# puts 'user_dir=' + @context.user_dir.to_s
|
113
|
+
@context.user_dir
|
114
|
+
end
|
115
|
+
|
116
|
+
def sw_set_data(data)
|
117
|
+
if data["attr_encoded"]
|
118
|
+
# new way, attributes are base 64 encoded
|
119
|
+
data = JSON.parse(Base64.decode64(data["attr_encoded"]))
|
120
|
+
end
|
121
|
+
|
122
|
+
data.each_pair do |k, v|
|
123
|
+
next unless k[0] == "@"
|
124
|
+
# puts "setting instance_variable #{k}=#{v}"
|
125
|
+
self.instance_variable_set(k, v)
|
126
|
+
end
|
127
|
+
|
128
|
+
end
|
129
|
+
|
130
|
+
def upload_if_needed(options={})
|
131
|
+
puts "No uploading in worker service."
|
132
|
+
end
|
133
|
+
|
134
|
+
alias_method :orig_queue, :queue
|
135
|
+
alias_method :orig_schedule, :schedule
|
136
|
+
alias_method :orig_status, :status
|
137
|
+
|
138
|
+
def queue(options={})
|
139
|
+
if SimpleWorker.queueing_enabled? && (!same_clazz? || options[:recursive])
|
140
|
+
orig_queue(options)
|
141
|
+
# data = sw_get_data()
|
142
|
+
# queue_other(self.class.name, data)
|
143
|
+
else
|
144
|
+
log (SimpleWorker.queueing_enabled? ? "WARNING: Recursion detected in queueing, pass in :recursive=>true to bypass this." : "Queuing disabled while loading.")
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
def schedule(schedule)
|
149
|
+
if SimpleWorker.queueing_enabled? && (!same_clazz? || schedule[:recursive])
|
150
|
+
orig_schedule(schedule)
|
151
|
+
# data = sw_get_data()
|
152
|
+
# schedule_other(self.class.name, data, schedule)
|
153
|
+
else
|
154
|
+
log (SimpleWorker.queueing_enabled? ? "WARNING: Recursion detected in scheduling." : "Scheduling disabled while loading.")
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
def status
|
160
|
+
if SimpleWorker.queueing_enabled?
|
161
|
+
orig_status
|
162
|
+
else
|
163
|
+
log "Status disabled while loading."
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
def same_clazz?
|
168
|
+
SimpleWorker.running_class == self.class
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
|
174
|
+
class Service < SimpleWorker::Api::Client
|
175
|
+
def upload(filename, class_name, options={})
|
176
|
+
#puts "Skipping upload, We don't upload from run.rb!"
|
177
|
+
# don't upload, should already be here.
|
178
|
+
end
|
179
|
+
|
180
|
+
def add_sw_params(hash_to_send)
|
181
|
+
hash_to_send["sw_access_key"] = self.access_key
|
182
|
+
hash_to_send["sw_secret_key"] = self.secret_key
|
183
|
+
hash_to_send["api_version"] = SimpleWorker.api_version
|
184
|
+
#if defined?(SimpleWorker::SingleRunner)
|
185
|
+
# #puts "IN SINGLE RUNNER"
|
186
|
+
# runners = ObjectSpace.each_object(SimpleWorker::SingleRunner)
|
187
|
+
# if runners
|
188
|
+
# single_runner = runners.first
|
189
|
+
# #puts "PUTTING PARENT TASK ID #{single_runner.instance_variable_get(:@parent_task_id)|| single_runner.instance_variable_get(:@task_id)}"
|
190
|
+
# hash_to_send["sw_parent_task_id"] =single_runner.instance_variable_get(:@parent_task_id)|| single_runner.instance_variable_get(:@task_id)
|
191
|
+
# end
|
192
|
+
#end
|
193
|
+
end
|
194
|
+
end
|
195
|
+
|
196
|
+
|
197
|
+
module UsedInWorker
|
198
|
+
def log(str)
|
199
|
+
puts str.to_s
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
|
204
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
# This is the file that gets executed on the server.
|
2
|
+
|
3
|
+
|
4
|
+
def init_database_connection(sw_config)
|
5
|
+
if sw_config
|
6
|
+
db_config = sw_config['database']
|
7
|
+
if db_config
|
8
|
+
#@logger.info "Connecting to database using ActiveRecord..."
|
9
|
+
require 'active_record'
|
10
|
+
ActiveRecord::Base.establish_connection(db_config)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_class_to_run(class_name)
|
16
|
+
runner_class = Kernel.const_get(class_name)
|
17
|
+
return runner_class
|
18
|
+
end
|
19
|
+
|
20
|
+
def init_runner(runner_class, job_data)
|
21
|
+
# ensure initialize takes no arguments
|
22
|
+
init_arity = runner_class.instance_method(:initialize).arity
|
23
|
+
if init_arity == 0 || init_arity == -1
|
24
|
+
# good. -1 can be if it's not defined at all
|
25
|
+
else
|
26
|
+
raise InvalidWorkerError, "Worker initialize method must accept zero arguments."
|
27
|
+
end
|
28
|
+
runner = runner_class.new
|
29
|
+
runner.instance_variable_set(:@job_data, job_data)
|
30
|
+
runner.instance_variable_set(:@sw_config, job_data['sw_config'])
|
31
|
+
runner.sw_set_data(job_data)
|
32
|
+
runner
|
33
|
+
end
|
34
|
+
|
35
|
+
def init_worker_service_for_runner(job_data)
|
36
|
+
SimpleWorker.configure do |config|
|
37
|
+
sw_config = job_data['sw_config']
|
38
|
+
config.access_key = sw_config['access_key']
|
39
|
+
config.secret_key = sw_config['secret_key']
|
40
|
+
#puts 'Setting host to ' + host.inspect
|
41
|
+
config.host = sw_config['host'] if sw_config['host']
|
42
|
+
db_config = sw_config['database']
|
43
|
+
if db_config
|
44
|
+
config.database = db_config
|
45
|
+
end
|
46
|
+
config.global_attributes = sw_config['global_attributes'] if sw_config['global_attributes']
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Find environment (-e)
|
51
|
+
dirname = ""
|
52
|
+
i = 0
|
53
|
+
job_data_file = run_data_file = nil
|
54
|
+
puts "args for single file=" + ARGV.inspect
|
55
|
+
ARGV.each do |arg|
|
56
|
+
if arg == "-d"
|
57
|
+
# the user's writable directory
|
58
|
+
dirname = ARGV[i+1]
|
59
|
+
end
|
60
|
+
if arg == "-j"
|
61
|
+
# path to job data
|
62
|
+
job_data_file = ARGV[i+1]
|
63
|
+
end
|
64
|
+
if arg == "-p"
|
65
|
+
# path to run data
|
66
|
+
run_data_file = ARGV[i+1]
|
67
|
+
end
|
68
|
+
i+=1
|
69
|
+
end
|
70
|
+
|
71
|
+
# Change to user directory
|
72
|
+
puts 'dirname=' + dirname.inspect
|
73
|
+
Dir.chdir(dirname)
|
74
|
+
|
75
|
+
run_data = JSON.load(File.open(run_data_file))
|
76
|
+
# Load in job data
|
77
|
+
job_data = JSON.load(File.open(job_data_file))
|
78
|
+
job_data.merge!(run_data)
|
79
|
+
puts 'job_data=' + job_data.inspect
|
80
|
+
|
81
|
+
sw_config = job_data['sw_config']
|
82
|
+
begin
|
83
|
+
init_database_connection(sw_config)
|
84
|
+
SimpleWorker.disable_queueing()
|
85
|
+
runner_class = get_class_to_run(job_data['class_name'])
|
86
|
+
SimpleWorker.running_class = runner_class
|
87
|
+
runner = init_runner(runner_class, job_data)
|
88
|
+
init_worker_service_for_runner(job_data)
|
89
|
+
SimpleWorker.enable_queueing()
|
90
|
+
|
91
|
+
# Let's run it!
|
92
|
+
runner_return_data = runner.run
|
93
|
+
rescue Exception => ex
|
94
|
+
$stderr.puts "_error_from_sw_"
|
95
|
+
raise ex
|
96
|
+
end
|
@@ -60,6 +60,7 @@ module SimpleWorker
|
|
60
60
|
options = {
|
61
61
|
"class_name"=>class_name,
|
62
62
|
"name"=>name,
|
63
|
+
"standalone"=>true,
|
63
64
|
"file_name"=> "runner.rb" # File.basename(filename)
|
64
65
|
}
|
65
66
|
#puts 'options for upload=' + options.inspect
|
@@ -115,15 +116,15 @@ module SimpleWorker
|
|
115
116
|
end
|
116
117
|
puts 'merged_gems_after=' + merged_gems.inspect
|
117
118
|
|
119
|
+
merged_mailers ||= {}
|
120
|
+
merged_mailers = merged_mailers.merge(SimpleWorker.config.mailers) if SimpleWorker.config.mailers
|
121
|
+
|
118
122
|
#tmp_file = File.join(Dir.tmpdir(), File.basename(filename))
|
119
123
|
tmp_file = File.join(Dir.tmpdir(), 'runner.rb')
|
120
124
|
File.open(tmp_file, "w") do |f|
|
121
125
|
# add some rails stuff if using Rails
|
122
126
|
|
123
|
-
|
124
|
-
SimpleWorker.logger.debug "merging #{k} into #{filename}"
|
125
|
-
f.write("require_relative '#{k}'\n") # add(File.basename(m), m)
|
126
|
-
end
|
127
|
+
f.write("require 'simple_worker'\n")
|
127
128
|
|
128
129
|
if defined?(Rails)
|
129
130
|
f.write "module Rails
|
@@ -136,51 +137,62 @@ module SimpleWorker
|
|
136
137
|
end
|
137
138
|
"
|
138
139
|
end
|
139
|
-
|
140
|
-
SimpleWorker.config.extra_requires.each do |r|
|
141
|
-
f.write "require '#{r}'\n"
|
142
|
-
end
|
143
|
-
end
|
140
|
+
|
144
141
|
if merged_mailers && !merged_mailers.empty?
|
145
142
|
# todo: isn't 'action_mailer already required in railtie?
|
146
143
|
f.write "require 'action_mailer'\n"
|
147
144
|
f.write "ActionMailer::Base.prepend_view_path('templates')\n"
|
148
145
|
end
|
149
146
|
#if SimpleWorker.config.auto_merge
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
end
|
147
|
+
merged_gems.each_pair do |k, gem|
|
148
|
+
puts "Bundling gem #{gem[:name]}..."
|
149
|
+
if gem[:merge]
|
150
|
+
f.write "$LOAD_PATH << File.join(File.dirname(__FILE__), '/gems/#{gem[:name]}/lib')\n"
|
151
|
+
end
|
156
152
|
# unless gem[:no_require]
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
end
|
168
|
-
# end
|
153
|
+
puts 'writing requires: ' + gem[:require].inspect
|
154
|
+
if gem[:require].nil?
|
155
|
+
gem[:require] = []
|
156
|
+
elsif gem[:require].is_a?(String)
|
157
|
+
gem[:require] = [gem[:require]]
|
158
|
+
end
|
159
|
+
puts gem[:require].inspect
|
160
|
+
gem[:require].each do |r|
|
161
|
+
puts 'adding require to file ' + r.to_s
|
162
|
+
f.write "require '#{r}'\n"
|
169
163
|
end
|
164
|
+
# end
|
170
165
|
end
|
171
|
-
|
172
|
-
|
173
|
-
|
166
|
+
|
167
|
+
if SimpleWorker.config.extra_requires
|
168
|
+
SimpleWorker.config.extra_requires.each do |r|
|
169
|
+
f.write "require '#{r}'\n"
|
174
170
|
end
|
175
171
|
end
|
176
|
-
|
177
|
-
|
178
|
-
|
172
|
+
|
173
|
+
File.open(File.join(File.dirname(__FILE__), 'server', 'overrides.rb'), 'r') do |fr|
|
174
|
+
while line = fr.gets
|
175
|
+
f.write line
|
179
176
|
end
|
180
177
|
end
|
178
|
+
|
179
|
+
merged.each_pair do |k, v|
|
180
|
+
f.write "require_relative '#{File.basename(v[:path])}'\n"
|
181
|
+
end
|
182
|
+
merged_mailers.each_pair do |k, mailer|
|
183
|
+
f.write "require_relative '#{mailer[:name]}'\n"
|
184
|
+
end
|
181
185
|
#end
|
182
186
|
#f.write File.open(filename, 'r') { |mo| mo.read }
|
183
187
|
f.write("require_relative '#{File.basename(filename)}'")
|
188
|
+
|
189
|
+
File.open(File.join(File.dirname(__FILE__), "server", 'runner.rb'), 'r') do |fr|
|
190
|
+
while line = fr.gets
|
191
|
+
f.write line
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
|
184
196
|
end
|
185
197
|
#puts 'funner.rb=' + tmp_file
|
186
198
|
merge['runner.rb'] = {:path=>tmp_file}
|
@@ -242,7 +254,7 @@ end
|
|
242
254
|
end
|
243
255
|
if merged_mailers && merged_mailers.size > 0
|
244
256
|
# puts " MERGED MAILERS" + merged_mailers.inspect
|
245
|
-
merged_mailers.
|
257
|
+
merged_mailers.each_pair do |k, mailer|
|
246
258
|
SimpleWorker.logger.debug "Collecting mailer #{mailer[:name]}"
|
247
259
|
f.add(File.basename(mailer[:filename]), mailer[:filename])
|
248
260
|
path = mailer[:path_to_templates]
|
@@ -281,16 +293,21 @@ end
|
|
281
293
|
if !data.is_a?(Array)
|
282
294
|
data = [data]
|
283
295
|
end
|
296
|
+
data.each do |d|
|
297
|
+
d['class_name'] = class_name
|
298
|
+
d['access_key'] = class_name
|
299
|
+
end
|
284
300
|
name = options[:name] || class_name
|
285
301
|
hash_to_send = {}
|
286
302
|
hash_to_send["payload"] = data
|
287
303
|
hash_to_send["class_name"] = class_name
|
288
304
|
hash_to_send["name"] = name
|
305
|
+
#hash_to_send["standalone"] = true # new school
|
289
306
|
hash_to_send["priority"] = options[:priority] if options[:priority]
|
290
307
|
hash_to_send["options"] = options
|
291
308
|
add_sw_params(hash_to_send)
|
292
309
|
if defined?(RAILS_ENV)
|
293
|
-
# todo:
|
310
|
+
# todo: REMOVE THIS
|
294
311
|
hash_to_send["rails_env"] = RAILS_ENV
|
295
312
|
end
|
296
313
|
return queue_raw(class_name, hash_to_send)
|
@@ -358,6 +375,12 @@ end
|
|
358
375
|
ret
|
359
376
|
end
|
360
377
|
|
378
|
+
# data is a hash, should include 'percent' and 'message'
|
379
|
+
def set_progress(task_id, data)
|
380
|
+
data={"data"=>data, "task_id"=>task_id}
|
381
|
+
post("task/setstatus", data)
|
382
|
+
end
|
383
|
+
|
361
384
|
def log(task_id)
|
362
385
|
data = {"task_id"=>task_id}
|
363
386
|
ret = get("task/log", data, {:parse=>false})
|
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: 0.
|
4
|
+
prerelease: 6
|
5
|
+
version: 1.0.0.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-11 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: zip
|
@@ -49,7 +49,8 @@ files:
|
|
49
49
|
- lib/simple_worker/api.rb
|
50
50
|
- lib/simple_worker/base.rb
|
51
51
|
- lib/simple_worker/config.rb
|
52
|
-
- lib/simple_worker/
|
52
|
+
- lib/simple_worker/server/overrides.rb
|
53
|
+
- lib/simple_worker/server/runner.rb
|
53
54
|
- lib/simple_worker/service.rb
|
54
55
|
- lib/simple_worker/used_in_worker.rb
|
55
56
|
- lib/simple_worker/utils.rb
|
@@ -72,9 +73,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
72
73
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
74
|
none: false
|
74
75
|
requirements:
|
75
|
-
- - "
|
76
|
+
- - ">"
|
76
77
|
- !ruby/object:Gem::Version
|
77
|
-
version:
|
78
|
+
version: 1.3.1
|
78
79
|
requirements: []
|
79
80
|
|
80
81
|
rubyforge_project:
|
data/lib/simple_worker/runner.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
# This is the file that gets executed on the server.
|