ext_batch 0.1.3 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +42 -5
- data/lib/ext_batch/main.rb +27 -22
- data/lib/ext_batch/version.rb +1 -1
- data/lib/templates/app/mailers/application_mailer.rb +15 -0
- data/lib/templates/config/initializers/sidekiq.rb +18 -0
- data/lib/templates/config/sidekiq.yml +26 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4ca7d0e5cb121d2905805aed2f0eec87e5578eb1
|
4
|
+
data.tar.gz: 7b6d7c5668add86a6a99fbafa2e7de3fd588843a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a469e9628fc50be1771f28d5d0ef8a15d889397b0d612982431654c7e9265fded3e5f57ad9266bf2aa184d12a4e9aba2978cbfca0bd737d1e3a61ac01838d374
|
7
|
+
data.tar.gz: 189486a5d7aaaee0a3351dedc7409148f6e9ed05e741582567a74775e165e3f9f88f77c0da5661bf1b8614386dd4bb75b2aaf027dc5132eeb0f656a694cf39de
|
data/README.md
CHANGED
@@ -5,9 +5,9 @@ Welcome to your new gem! In this directory, you'll find the files you need to be
|
|
5
5
|
```explain
|
6
6
|
Extended the ext_logger gem package, services for Ruby batch and Ruby rake.
|
7
7
|
Other extensions see version updates.
|
8
|
-
2019-01-20(0.1.
|
8
|
+
2019-01-20(0.1.4):
|
9
9
|
dependency: ext_logger ~> v0.2
|
10
|
-
|
10
|
+
Add configuration for batch mail.
|
11
11
|
|
12
12
|
```
|
13
13
|
|
@@ -15,9 +15,7 @@ Other extensions see version updates.
|
|
15
15
|
|
16
16
|
Add this line to your application's Gemfile:
|
17
17
|
|
18
|
-
|
19
|
-
gem 'ext_batch'
|
20
|
-
```
|
18
|
+
gem 'ext_batch'
|
21
19
|
|
22
20
|
And then execute:
|
23
21
|
|
@@ -26,6 +24,23 @@ And then execute:
|
|
26
24
|
Or install it yourself as:
|
27
25
|
|
28
26
|
$ gem install ext_batch
|
27
|
+
|
28
|
+
## Configure
|
29
|
+
|
30
|
+
Mail configuration, add the following configuration to the Application Mailer file.
|
31
|
+
```ruby
|
32
|
+
# add to application_mailer.rb
|
33
|
+
def send_batch_mail(to, title, body)
|
34
|
+
mail_hash = {
|
35
|
+
to: to,
|
36
|
+
subject: title,
|
37
|
+
body: body,
|
38
|
+
content_type: 'text/html',
|
39
|
+
}
|
40
|
+
|
41
|
+
mail(mail_hash)
|
42
|
+
end
|
43
|
+
```
|
29
44
|
|
30
45
|
## Usage
|
31
46
|
|
@@ -68,6 +83,28 @@ Or install it yourself as:
|
|
68
83
|
batch.end
|
69
84
|
```
|
70
85
|
|
86
|
+
## Example:
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
# In rake batch_name = task
|
90
|
+
# In ruby file batch_name = File.basename(__FILE__).gsub('.rb', '')
|
91
|
+
# In method batch_name = __method__
|
92
|
+
|
93
|
+
batch = ExtBatch.new(batch_name)
|
94
|
+
begin
|
95
|
+
batch.info 'info message'
|
96
|
+
batch.error 'error message'
|
97
|
+
...
|
98
|
+
|
99
|
+
batch.mail_ok({to: 'mailname@maildomain.com', content: 'mail content.'})
|
100
|
+
batch.mail_ok({to: 'mailname@maildomain.com', content: 'mail content.'})
|
101
|
+
...
|
102
|
+
rescue Exception => e
|
103
|
+
batch.exception(e, {send_mail: true/false})
|
104
|
+
end
|
105
|
+
batch.end
|
106
|
+
```
|
107
|
+
|
71
108
|
## Development
|
72
109
|
|
73
110
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/ext_batch/main.rb
CHANGED
@@ -190,10 +190,7 @@ class ExtBatch
|
|
190
190
|
content << analysis_exception(e)
|
191
191
|
content << opt[:content] if !is_blank?(opt[:content])
|
192
192
|
|
193
|
-
|
194
|
-
when SEND_MAIL_YES
|
195
|
-
mail_error({content: content.join("\n")})
|
196
|
-
end
|
193
|
+
mail_error({content: content.join("\n")}) if opt[:send_mail] == SEND_MAIL_YES
|
197
194
|
error(content)
|
198
195
|
end
|
199
196
|
|
@@ -323,6 +320,8 @@ class ExtBatch
|
|
323
320
|
# batch: send tips mail
|
324
321
|
def mail_tips(task_name, opt={})
|
325
322
|
func_name = "[#{get_class_name}:private #{__method__.to_s}]"
|
323
|
+
opt[:from] ||= ''
|
324
|
+
opt[:to] ||= ''
|
326
325
|
opt[:content] ||= ''
|
327
326
|
_status = opt[:status] || LABEL_OK
|
328
327
|
|
@@ -337,16 +336,16 @@ class ExtBatch
|
|
337
336
|
message_body = result.join("\n")
|
338
337
|
# info message_body
|
339
338
|
|
340
|
-
|
339
|
+
mail_option = {
|
340
|
+
to: opt[:to],
|
341
341
|
title: "BATCH #{_status}: #{task_name} (#{Time.now})",
|
342
|
-
body:
|
342
|
+
body: message_body.gsub("\n", "<br />"),
|
343
343
|
status: _status
|
344
344
|
}
|
345
345
|
|
346
|
-
_option = _option.merge({body: message_body})
|
347
346
|
message = "### Next is detail of mail ###\n"
|
348
|
-
message += "[TITLE]: #{
|
349
|
-
message += "[BODY]:\n #{
|
347
|
+
message += "[TITLE]: #{mail_option[:title]}\n"
|
348
|
+
message += "[BODY]:\n #{message_body}\n"
|
350
349
|
|
351
350
|
case _status
|
352
351
|
when LABEL_ERROR
|
@@ -361,24 +360,30 @@ class ExtBatch
|
|
361
360
|
|
362
361
|
if defined? ActionMailer
|
363
362
|
mail_flag = true
|
364
|
-
if is_blank?(opt[:to]) && is_blank?(opt[:
|
363
|
+
if is_blank?(opt[:to]) && is_blank?(opt[:content])
|
365
364
|
@ext_logger.error "#{func_name} Mail delivery failed, parameters error. opt: #{opt}"
|
366
365
|
mail_flag = false
|
367
366
|
end
|
368
367
|
|
369
368
|
if mail_flag
|
370
|
-
mail_option = {
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
#
|
376
|
-
|
377
|
-
|
378
|
-
mail_option = mail_option.merge(:template_path => opt[:template_path]) if !opt[:template_path]
|
379
|
-
mail_option = mail_option.merge(:template_name => opt[:template_name]) if !opt[:template_name]
|
380
|
-
|
381
|
-
|
369
|
+
# mail_option = {
|
370
|
+
# from: opt[:from],
|
371
|
+
# to: opt[:to],
|
372
|
+
# content_type: 'text/html',
|
373
|
+
# subject: _option[:title],
|
374
|
+
# body: _option[:body]
|
375
|
+
# }
|
376
|
+
# # logger.info "set_mail", mail_hash
|
377
|
+
# mail_option = mail_option.merge(:template_path => opt[:template_path]) if !is_blank?(opt[:template_path])
|
378
|
+
# mail_option = mail_option.merge(:template_name => opt[:template_name]) if !is_blank?(opt[:template_name])
|
379
|
+
# mail(mail_option)
|
380
|
+
|
381
|
+
begin
|
382
|
+
ApplicationMailer.send_batch_mail(mail_option[:to], mail_option[:title], mail_option[:body]).deliver
|
383
|
+
@ext_logger.info "Batch mail send OK."
|
384
|
+
rescue Exception => e
|
385
|
+
@ext_logger.exception e
|
386
|
+
end
|
382
387
|
end
|
383
388
|
else
|
384
389
|
@ext_logger.warn "#{func_name} Mail delivery failed, not found ActionMailer class."
|
data/lib/ext_batch/version.rb
CHANGED
@@ -0,0 +1,15 @@
|
|
1
|
+
class ApplicationMailer < ActionMailer::Base
|
2
|
+
default from: 'from@example.com'
|
3
|
+
layout 'mailer'
|
4
|
+
|
5
|
+
def send_batch_mail(to, title, body)
|
6
|
+
mail_hash = {
|
7
|
+
to: to,
|
8
|
+
subject: title,
|
9
|
+
body: body,
|
10
|
+
content_type: 'text/html',
|
11
|
+
}
|
12
|
+
|
13
|
+
mail(mail_hash)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
if Rails.env.production?
|
2
|
+
redis_server = '127.0.0.1'
|
3
|
+
elsif Rails.env.staging?
|
4
|
+
redis_server = '127.0.0.1'
|
5
|
+
else
|
6
|
+
redis_server = '127.0.0.1'
|
7
|
+
end
|
8
|
+
|
9
|
+
redis_port = 6379
|
10
|
+
redis_db_num = 1
|
11
|
+
redis_namespace = 'batch_monitor'
|
12
|
+
|
13
|
+
Sidekiq.configure_server do |config|
|
14
|
+
config.redis = { url: "redis://#{redis_server}:#{redis_port}/#{redis_db_num}", namespace: redis_namespace }
|
15
|
+
config.on(:startup) do
|
16
|
+
Sidekiq::Scheduler.reload_schedule!
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
:concurrency: 5
|
2
|
+
:pidfile: tmp/pids/sidekiq.pid
|
3
|
+
:logfile: ./log/sidekiq.log
|
4
|
+
:timeout: 10
|
5
|
+
:queues:
|
6
|
+
- default # 写在队列参数中的, 表示让 sidekiq 处理这个 queue
|
7
|
+
- [batch_monitor, 5] # 使用数组的形式写, 第一个参数为打开的 queue 的名称, 第二个为优先级
|
8
|
+
|
9
|
+
sidekiq_schedule: &run_work
|
10
|
+
# 配置worker
|
11
|
+
:schedule:
|
12
|
+
ext_batch_monitor:
|
13
|
+
every: '4s'
|
14
|
+
class: ExtBatchMonitor
|
15
|
+
development:
|
16
|
+
<<: *run_work
|
17
|
+
:concurrency: 20
|
18
|
+
stage:
|
19
|
+
<<: *run_work
|
20
|
+
:concurrency: 30
|
21
|
+
production:
|
22
|
+
<<: *run_work
|
23
|
+
:concurrency: 40
|
24
|
+
|
25
|
+
|
26
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ext_batch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ruby
|
@@ -104,6 +104,9 @@ files:
|
|
104
104
|
- lib/ext_batch/main.rb
|
105
105
|
- lib/ext_batch/version.rb
|
106
106
|
- lib/tasks/ext_batch.rake
|
107
|
+
- lib/templates/app/mailers/application_mailer.rb
|
108
|
+
- lib/templates/config/initializers/sidekiq.rb
|
109
|
+
- lib/templates/config/sidekiq.yml
|
107
110
|
- lib/templates/workers/ext_batch_monitor.rb
|
108
111
|
homepage: ''
|
109
112
|
licenses:
|