simple_worker 1.0.10 → 1.0.11
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +29 -0
- data/lib/simple_worker/base.rb +9 -0
- data/lib/simple_worker/config.rb +6 -0
- data/lib/simple_worker/server/runner.rb +18 -6
- data/lib/simple_worker/service.rb +8 -3
- metadata +2 -2
data/README.markdown
CHANGED
@@ -263,6 +263,23 @@ You could easily merge mailers you're using in your application.
|
|
263
263
|
|
264
264
|
if you already set auto_merge=true all your mailers already merged.
|
265
265
|
|
266
|
+
Configuring a Mailer Connection
|
267
|
+
|
268
|
+
If you are using Rails 3,your action_mailer connection would be configured automatically from your config
|
269
|
+
|
270
|
+
For non Rails 3 or if you want to use different mailer configs, you should add the following to your SimpleWorker config:
|
271
|
+
|
272
|
+
config.mailer = {
|
273
|
+
:address => "smtp.gmail.com",
|
274
|
+
:port => 587,
|
275
|
+
:domain => 'gmail.com',
|
276
|
+
:user_name => GMAIL_USERNAME
|
277
|
+
:password => GMAIL_PASSWORD
|
278
|
+
:authentication => 'plain',
|
279
|
+
:enable_starttls_auto => true}
|
280
|
+
|
281
|
+
Then before you job is run, SimpleWorker will establish the ActionMailer connection.
|
282
|
+
|
266
283
|
Merging Gems
|
267
284
|
---------------------
|
268
285
|
|
@@ -280,6 +297,18 @@ This allows you to use any gem you'd like with SimpleWorker. This uses the same
|
|
280
297
|
|
281
298
|
[Check here for more info on merge_gem](http://support.simpleworker.com/kb/working-with-simpleworker/merging-gems-into-your-worker).
|
282
299
|
|
300
|
+
|
301
|
+
Job Timeout
|
302
|
+
--------------
|
303
|
+
|
304
|
+
By default, each job has 60 minutes (3600 seconds to complete). If you know that your job should take less than that, you can specify a timeout explicitly:
|
305
|
+
|
306
|
+
worker.queue(:timeout=>1800)
|
307
|
+
|
308
|
+
This will kill your job if it is running more than 1800 seconds, or half an hour.
|
309
|
+
|
310
|
+
|
311
|
+
|
283
312
|
Global Merging
|
284
313
|
--------------
|
285
314
|
|
data/lib/simple_worker/base.rb
CHANGED
@@ -151,6 +151,7 @@ module SimpleWorker
|
|
151
151
|
# puts 'run_local'
|
152
152
|
set_auto_attributes
|
153
153
|
init_database
|
154
|
+
init_mailer
|
154
155
|
begin
|
155
156
|
run
|
156
157
|
rescue => ex
|
@@ -162,6 +163,14 @@ module SimpleWorker
|
|
162
163
|
end
|
163
164
|
end
|
164
165
|
|
166
|
+
def init_mailer
|
167
|
+
if SimpleWorker.config.mailer
|
168
|
+
require 'action_mailer'
|
169
|
+
ActionMailer::Base.raise_delivery_errors = true
|
170
|
+
ActionMailer::Base.smtp_settings = (SimpleWorker.config.mailer)
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
165
174
|
def init_database
|
166
175
|
if SimpleWorker.config.database
|
167
176
|
require 'active_record'
|
data/lib/simple_worker/config.rb
CHANGED
@@ -18,6 +18,7 @@ module SimpleWorker
|
|
18
18
|
:mailers,
|
19
19
|
#:gems, # todo: move anything that uses this to merged_gems
|
20
20
|
:database,
|
21
|
+
:mailer,
|
21
22
|
:extra_requires,
|
22
23
|
#:auto_merge,
|
23
24
|
:server_gems,
|
@@ -70,6 +71,10 @@ module SimpleWorker
|
|
70
71
|
else
|
71
72
|
#puts 'NOT DOING ACTIVERECORD'
|
72
73
|
end
|
74
|
+
|
75
|
+
if defined?(ActionMailer) && ActionMailer::Base.smtp_settings
|
76
|
+
c2.mailer = ActionMailer::Base.smtp_settings
|
77
|
+
end
|
73
78
|
c2.merged_gems.merge!(get_required_gems) if defined?(Bundler)
|
74
79
|
SimpleWorker.logger.debug "MODELS " + c2.models.inspect
|
75
80
|
SimpleWorker.logger.debug "MAILERS " + c2.mailers.inspect
|
@@ -146,6 +151,7 @@ module SimpleWorker
|
|
146
151
|
config_data['access_key'] = access_key
|
147
152
|
config_data['secret_key'] = secret_key
|
148
153
|
config_data['database'] = self.database if self.database
|
154
|
+
config_data['mailer'] = self.mailer if self.mailer
|
149
155
|
config_data['global_attributes'] = self.global_attributes if self.global_attributes
|
150
156
|
config_data['host'] = self.host if self.host
|
151
157
|
config_data
|
@@ -12,6 +12,18 @@ def init_database_connection(sw_config)
|
|
12
12
|
end
|
13
13
|
end
|
14
14
|
|
15
|
+
def init_mailer(sw_config)
|
16
|
+
if sw_config
|
17
|
+
mailer_config = sw_config['mailer']
|
18
|
+
if mailer_config
|
19
|
+
require 'action_mailer'
|
20
|
+
ActionMailer::Base.raise_delivery_errors = true
|
21
|
+
ActionMailer::Base.smtp_settings = mailer_config
|
22
|
+
ActionMailer::Base.delivery_method = :smtp
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
15
27
|
def get_class_to_run(class_name)
|
16
28
|
runner_class = constantize(class_name)
|
17
29
|
return runner_class
|
@@ -57,6 +69,10 @@ def init_worker_service_for_runner(job_data)
|
|
57
69
|
if db_config
|
58
70
|
config.database = db_config
|
59
71
|
end
|
72
|
+
mailer_config = sw_config['mailer']
|
73
|
+
if mailer_config && config.respond_to?(:mailer)
|
74
|
+
config.mailer = mailer_config
|
75
|
+
end
|
60
76
|
config.global_attributes = sw_config['global_attributes'] if sw_config['global_attributes']
|
61
77
|
end
|
62
78
|
end
|
@@ -69,8 +85,8 @@ job_data.merge!(run_data)
|
|
69
85
|
puts 'job_data=' + job_data.inspect
|
70
86
|
|
71
87
|
sw_config = job_data['sw_config']
|
72
|
-
begin
|
73
88
|
init_database_connection(sw_config)
|
89
|
+
init_mailer(sw_config)
|
74
90
|
SimpleWorker.disable_queueing()
|
75
91
|
runner_class = get_class_to_run(job_data['class_name'])
|
76
92
|
SimpleWorker.running_class = runner_class
|
@@ -79,8 +95,4 @@ begin
|
|
79
95
|
SimpleWorker.enable_queueing()
|
80
96
|
|
81
97
|
# Let's run it!
|
82
|
-
runner_return_data = runner.run
|
83
|
-
rescue Exception => ex
|
84
|
-
$stderr.puts "_error_from_sw_"
|
85
|
-
raise ex
|
86
|
-
end
|
98
|
+
runner_return_data = runner.run
|
@@ -122,10 +122,10 @@ module SimpleWorker
|
|
122
122
|
#tmp_file = File.join(Dir.tmpdir(), File.basename(filename))
|
123
123
|
tmp_file = File.join(Dir.tmpdir(), 'runner.rb')
|
124
124
|
File.open(tmp_file, "w") do |f|
|
125
|
-
|
125
|
+
f.write("begin\n")#error handling block start
|
126
126
|
f.write("
|
127
127
|
# Find environment (-e)
|
128
|
-
dirname =
|
128
|
+
dirname = ''
|
129
129
|
i = 0
|
130
130
|
job_data_file = run_data_file = nil
|
131
131
|
puts \"args for single file=\" + ARGV.inspect
|
@@ -226,7 +226,12 @@ end
|
|
226
226
|
f.write line
|
227
227
|
end
|
228
228
|
end
|
229
|
-
|
229
|
+
#error handling block - end
|
230
|
+
f.write("\nrescue Exception => ex
|
231
|
+
$stderr.puts '_error_from_sw_'
|
232
|
+
raise ex
|
233
|
+
end
|
234
|
+
")
|
230
235
|
|
231
236
|
end
|
232
237
|
#puts 'funner.rb=' + tmp_file
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: simple_worker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.0.
|
5
|
+
version: 1.0.11
|
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-09-
|
13
|
+
date: 2011-09-28 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: zip
|