bizside 2.0.4 → 2.0.7
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/lib/bizside/config.rb +5 -3
- data/lib/bizside/file_uploader.rb +16 -6
- data/lib/bizside/job_utils.rb +35 -0
- data/lib/bizside/resque.rb +14 -0
- data/lib/bizside/resque.rb.bkp +161 -0
- data/lib/bizside/resque.rb~ +154 -0
- data/lib/bizside/version.rb +1 -1
- data/lib/bizside/version.rb~ +3 -0
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f00dba55e99db77fad3ddfe68afb706b89fe3bdc718ad774613309c3bebb7d7e
|
4
|
+
data.tar.gz: 16be628bb79ff1689956d1f63f0895559775531b74d80270d7edb6239ef9abf3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a2c0f432bd5d53b537f9db6b3a7f28a9f0c747b9eb0a49ec0838ec02ecfbdedc902d36bda002581d82cbaf5513f0177d5ac57fa229604fde0516bf729b1df9fb
|
7
|
+
data.tar.gz: b28b49b0f10c14bedf018a61d938465de5a95d4a8884a9721bf25291c08eec807e2017bad15d6d1594a4f0c82c971b3d70ee1d63502ad94ace3a6000f9ff54ea
|
data/lib/bizside/config.rb
CHANGED
@@ -25,7 +25,7 @@ module Bizside
|
|
25
25
|
|
26
26
|
ret
|
27
27
|
end
|
28
|
-
|
28
|
+
|
29
29
|
def []=(key, value)
|
30
30
|
value = self.class.new(value) if value.is_a?(Hash)
|
31
31
|
@hash[key.to_s] = value
|
@@ -52,8 +52,10 @@ module Bizside
|
|
52
52
|
def method_missing(name, *args)
|
53
53
|
ret = self[name]
|
54
54
|
|
55
|
-
if ret.is_a?(Hash)
|
56
|
-
|
55
|
+
if ret.is_a?(Hash) || ret.is_a?(::Bizside::Config)
|
56
|
+
unless args[0].nil?
|
57
|
+
ret = self[name] = args[0]
|
58
|
+
end
|
57
59
|
end
|
58
60
|
|
59
61
|
ret
|
@@ -4,12 +4,7 @@ require_relative 'carrierwave'
|
|
4
4
|
require_relative 'uploader/extension_whitelist'
|
5
5
|
require_relative 'uploader/filename_validator'
|
6
6
|
require_relative 'uploader/content_type_validator'
|
7
|
-
|
8
|
-
if defined?(Rails) && Rails.application.class.parent_name.eql?('BizsideTestApp')
|
9
|
-
# not require 'uploader/exif'
|
10
|
-
else
|
11
|
-
require_relative 'uploader/exif'
|
12
|
-
end
|
7
|
+
require_relative 'uploader/exif'
|
13
8
|
|
14
9
|
module Bizside
|
15
10
|
# === storage.yml
|
@@ -45,6 +40,21 @@ module Bizside
|
|
45
40
|
Bizside.config.storage.fog? ? downloaded_file_from_fog(file.path) : file.path
|
46
41
|
end
|
47
42
|
|
43
|
+
# ファイル名の長さチェックが可能なように
|
44
|
+
def cache!(new_file = sanitized_file)
|
45
|
+
begin
|
46
|
+
super
|
47
|
+
rescue Errno::ENAMETOOLONG => e
|
48
|
+
if Bizside.config.file_uploader.ignore_long_filename_error?
|
49
|
+
if self.model.respond_to?(:original_filename)
|
50
|
+
self.model.original_filename = filename
|
51
|
+
end
|
52
|
+
else
|
53
|
+
raise e
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
48
58
|
private
|
49
59
|
|
50
60
|
def downloaded_file_from_fog(path)
|
data/lib/bizside/job_utils.rb
CHANGED
@@ -47,6 +47,41 @@ module Bizside
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
50
|
+
def self.enqueue_at_with_queue(queue, time, klass, *args)
|
51
|
+
if Bizside.rails_env&.test?
|
52
|
+
if klass.respond_to?(:before_enqueue)
|
53
|
+
return unless klass.before_enqueue(*args)
|
54
|
+
end
|
55
|
+
|
56
|
+
Bizside.logger.info "テスト時には遅延ジョブの登録を行わず、即時実行します。"
|
57
|
+
klass.perform(*args)
|
58
|
+
return
|
59
|
+
end
|
60
|
+
|
61
|
+
if block_given?
|
62
|
+
yield
|
63
|
+
else
|
64
|
+
Bizside.logger.info "遅延ジョブ #{klass} を #{queue} に登録します。"
|
65
|
+
end
|
66
|
+
|
67
|
+
::Resque.enqueue_at_with_queue(queue, time, klass, *args)
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.enqueue_at_with_queue_silently(queue, time, klass, *args)
|
71
|
+
enqueue_at_with_queue(queue, time, klass, *args) do
|
72
|
+
# 何も出力しない
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def self.remove_delayed_in_queue(klass, queue, *args)
|
77
|
+
if Bizside.rails_env&.test?
|
78
|
+
Rails.logger.info "テスト時には遅延ジョブのキャンセルを行いません。"
|
79
|
+
return
|
80
|
+
end
|
81
|
+
|
82
|
+
::Resque.remove_delayed_in_queue(klass, queue, *args)
|
83
|
+
end
|
84
|
+
|
50
85
|
def self.set_job_at(time, klass, *args)
|
51
86
|
if Bizside.rails_env&.test?
|
52
87
|
if klass.respond_to?(:before_enqueue)
|
data/lib/bizside/resque.rb
CHANGED
@@ -121,6 +121,7 @@ module Resque
|
|
121
121
|
info = {
|
122
122
|
time: Time.now.strftime('%Y-%m-%dT%H:%M:%S.%3N%z'),
|
123
123
|
add_on_name: Bizside.config.add_on_name,
|
124
|
+
server_address: hostname,
|
124
125
|
class: payload['class'],
|
125
126
|
args: payload['args'].to_s,
|
126
127
|
queue: queue,
|
@@ -132,6 +133,19 @@ module Resque
|
|
132
133
|
info
|
133
134
|
end
|
134
135
|
|
136
|
+
# ホスト名を取得。
|
137
|
+
#
|
138
|
+
# 下記理由から hostname(1) を使用:
|
139
|
+
#
|
140
|
+
# * job 実行環境では環境変数 HOSTNAME がセットされていないケースがある
|
141
|
+
# (例: 通常の god 起動の場合。他方、container 起動の場合は
|
142
|
+
# HOSTNAME がセットされている模様)。
|
143
|
+
# * hostname(1) は Linux Standard Base 共通コマンドのため必ず存在する。
|
144
|
+
# @see https://refspecs.linuxfoundation.org/LSB_5.0.0/LSB-Common/LSB-Common/rcommands.html
|
145
|
+
def hostname
|
146
|
+
@hostname ||= (`hostname`.chomp rescue '(unknown)')
|
147
|
+
end
|
148
|
+
|
135
149
|
end
|
136
150
|
end
|
137
151
|
end
|
@@ -0,0 +1,161 @@
|
|
1
|
+
module Bizside
|
2
|
+
module Resque
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'resque'
|
7
|
+
require 'resque/worker'
|
8
|
+
require 'resque/failure/base'
|
9
|
+
require 'resque/failure/multiple'
|
10
|
+
require 'resque/failure/redis'
|
11
|
+
require_relative 'audit/job_logger'
|
12
|
+
|
13
|
+
{
|
14
|
+
yaml: ['config/resque.yml', 'config/redis.yml'],
|
15
|
+
json: ['config/resque.json', 'config/redis.json']
|
16
|
+
}.each do |format, file_candidates|
|
17
|
+
file_candidates.each do |file|
|
18
|
+
resque_file = File.join(File.expand_path(ENV['RAILS_ROOT'] || '.'), file)
|
19
|
+
next unless File.exist?(resque_file)
|
20
|
+
|
21
|
+
resque_config = ERB.new(File.read(resque_file), 0, '-').result
|
22
|
+
|
23
|
+
case format
|
24
|
+
when :yaml
|
25
|
+
Resque.redis = YAML.load(resque_config)[Bizside.env]
|
26
|
+
break
|
27
|
+
when :json
|
28
|
+
Resque.redis = ActiveSupport::JSON.decode(resque_config)[Bizside.env]
|
29
|
+
break
|
30
|
+
else
|
31
|
+
raise "不正なResque設定ファイルです。#{file}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Resque.redis.namespace = "resque:#{Bizside.config.add_on_name}:#{Bizside.env}"
|
37
|
+
|
38
|
+
if defined?(Resque::Scheduler)
|
39
|
+
Resque::Scheduler.dynamic = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# tmp/stop.txt が存在する場合は一時停止する
|
43
|
+
module Resque
|
44
|
+
class Worker
|
45
|
+
|
46
|
+
alias_method :reserve_without_stop_txt, :reserve
|
47
|
+
|
48
|
+
def reserve
|
49
|
+
stop_file_path = File.join('tmp', 'stop.txt')
|
50
|
+
if File.exist?(stop_file_path)
|
51
|
+
puts "#{Resque.redis.namespace} #{stop_file_path} が存在するため一時停止します。"
|
52
|
+
nil
|
53
|
+
else
|
54
|
+
reserve_without_stop_txt
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# resque-webのエラーメッセージ文字化けに対するパッチ
|
62
|
+
module Resque
|
63
|
+
module Failure
|
64
|
+
class Redis
|
65
|
+
|
66
|
+
def save
|
67
|
+
data = {
|
68
|
+
:failed_at => UTF8Util.clean(Time.now.strftime("%Y/%m/%d %H:%M:%S %Z")),
|
69
|
+
:payload => payload,
|
70
|
+
:exception => exception.class.to_s,
|
71
|
+
:error => exception.to_s, #UTF8Util.clean(exception.to_s), UTF8Util.cleanを呼ぶと文字化けする
|
72
|
+
:backtrace => filter_backtrace(Array(exception.backtrace)),
|
73
|
+
:worker => worker.to_s,
|
74
|
+
:queue => queue
|
75
|
+
}
|
76
|
+
data = Resque.encode(data)
|
77
|
+
Resque.redis.rpush(:failed, data)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# エラーをログに出力
|
85
|
+
module Resque
|
86
|
+
module Failure
|
87
|
+
class LogOutput < Base
|
88
|
+
def save
|
89
|
+
Bizside.logger.error [
|
90
|
+
"[FATAL] Resque #{queue}:#{worker}",
|
91
|
+
"#{payload}",
|
92
|
+
"#{exception.class} #{exception.to_s}",
|
93
|
+
"#{Array(exception.backtrace).join("\n")}"
|
94
|
+
].join("\n")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# エラーをLTSV形式で専用ログに出力
|
101
|
+
module Resque
|
102
|
+
module Failure
|
103
|
+
class JobAuditLog < Base
|
104
|
+
|
105
|
+
def save
|
106
|
+
dump_env
|
107
|
+
info = build_loginfo
|
108
|
+
return info if Bizside.rails_env&.test?
|
109
|
+
|
110
|
+
logger.record(info)
|
111
|
+
|
112
|
+
info
|
113
|
+
end
|
114
|
+
|
115
|
+
private
|
116
|
+
|
117
|
+
def logger
|
118
|
+
@logger ||= Bizside::Audit::JobLogger.logger
|
119
|
+
end
|
120
|
+
|
121
|
+
def build_loginfo
|
122
|
+
info = {
|
123
|
+
time: Time.now.strftime('%Y-%m-%dT%H:%M:%S.%3N%z'),
|
124
|
+
add_on_name: Bizside.config.add_on_name,
|
125
|
+
server_address: hostname,
|
126
|
+
class: payload['class'],
|
127
|
+
args: payload['args'].to_s,
|
128
|
+
queue: queue,
|
129
|
+
worker: worker.to_s,
|
130
|
+
exception: exception.class,
|
131
|
+
exception_message: exception.to_s,
|
132
|
+
exception_backtrace: Array(exception.backtrace)[0..10].join("\n") # Get only the top 10 because there are many traces.
|
133
|
+
}
|
134
|
+
info
|
135
|
+
end
|
136
|
+
|
137
|
+
|
138
|
+
def dump_env
|
139
|
+
File.open('/tmp/resque-dump.log', 'a') do |f|
|
140
|
+
f.puts('== begin')
|
141
|
+
for k, v in ENV do
|
142
|
+
f.printf("%30s %s\n", k, v)
|
143
|
+
end
|
144
|
+
f.puts('')
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
# hostname(1) からホスト名を取得。
|
149
|
+
#
|
150
|
+
# job 実行環境(コンテナ等)では環境変数(HOSTNAME等)にホスト名はセットされていない。
|
151
|
+
def hostname
|
152
|
+
@hostname ||= (`hostname`.chomp rescue '(unknown)')
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
Resque::Failure::Multiple.configure do |multi|
|
160
|
+
multi.classes = [Resque::Failure::Redis, Resque::Failure::LogOutput, Resque::Failure::JobAuditLog]
|
161
|
+
end
|
@@ -0,0 +1,154 @@
|
|
1
|
+
module Bizside
|
2
|
+
module Resque
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'resque'
|
7
|
+
require 'resque/worker'
|
8
|
+
require 'resque/failure/base'
|
9
|
+
require 'resque/failure/multiple'
|
10
|
+
require 'resque/failure/redis'
|
11
|
+
require_relative 'audit/job_logger'
|
12
|
+
|
13
|
+
{
|
14
|
+
yaml: ['config/resque.yml', 'config/redis.yml'],
|
15
|
+
json: ['config/resque.json', 'config/redis.json']
|
16
|
+
}.each do |format, file_candidates|
|
17
|
+
file_candidates.each do |file|
|
18
|
+
resque_file = File.join(File.expand_path(ENV['RAILS_ROOT'] || '.'), file)
|
19
|
+
next unless File.exist?(resque_file)
|
20
|
+
|
21
|
+
resque_config = ERB.new(File.read(resque_file), 0, '-').result
|
22
|
+
|
23
|
+
case format
|
24
|
+
when :yaml
|
25
|
+
Resque.redis = YAML.load(resque_config)[Bizside.env]
|
26
|
+
break
|
27
|
+
when :json
|
28
|
+
Resque.redis = ActiveSupport::JSON.decode(resque_config)[Bizside.env]
|
29
|
+
break
|
30
|
+
else
|
31
|
+
raise "不正なResque設定ファイルです。#{file}"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Resque.redis.namespace = "resque:#{Bizside.config.add_on_name}:#{Bizside.env}"
|
37
|
+
|
38
|
+
if defined?(Resque::Scheduler)
|
39
|
+
Resque::Scheduler.dynamic = true
|
40
|
+
end
|
41
|
+
|
42
|
+
# tmp/stop.txt が存在する場合は一時停止する
|
43
|
+
module Resque
|
44
|
+
class Worker
|
45
|
+
|
46
|
+
alias_method :reserve_without_stop_txt, :reserve
|
47
|
+
|
48
|
+
def reserve
|
49
|
+
stop_file_path = File.join('tmp', 'stop.txt')
|
50
|
+
if File.exist?(stop_file_path)
|
51
|
+
puts "#{Resque.redis.namespace} #{stop_file_path} が存在するため一時停止します。"
|
52
|
+
nil
|
53
|
+
else
|
54
|
+
reserve_without_stop_txt
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
# resque-webのエラーメッセージ文字化けに対するパッチ
|
62
|
+
module Resque
|
63
|
+
module Failure
|
64
|
+
class Redis
|
65
|
+
|
66
|
+
def save
|
67
|
+
data = {
|
68
|
+
:failed_at => UTF8Util.clean(Time.now.strftime("%Y/%m/%d %H:%M:%S %Z")),
|
69
|
+
:payload => payload,
|
70
|
+
:exception => exception.class.to_s,
|
71
|
+
:error => exception.to_s, #UTF8Util.clean(exception.to_s), UTF8Util.cleanを呼ぶと文字化けする
|
72
|
+
:backtrace => filter_backtrace(Array(exception.backtrace)),
|
73
|
+
:worker => worker.to_s,
|
74
|
+
:queue => queue
|
75
|
+
}
|
76
|
+
data = Resque.encode(data)
|
77
|
+
Resque.redis.rpush(:failed, data)
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
# エラーをログに出力
|
85
|
+
module Resque
|
86
|
+
module Failure
|
87
|
+
class LogOutput < Base
|
88
|
+
def save
|
89
|
+
Bizside.logger.error [
|
90
|
+
"[FATAL] Resque #{queue}:#{worker}",
|
91
|
+
"#{payload}",
|
92
|
+
"#{exception.class} #{exception.to_s}",
|
93
|
+
"#{Array(exception.backtrace).join("\n")}"
|
94
|
+
].join("\n")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
# エラーをLTSV形式で専用ログに出力
|
101
|
+
module Resque
|
102
|
+
module Failure
|
103
|
+
class JobAuditLog < Base
|
104
|
+
|
105
|
+
def save
|
106
|
+
info = build_loginfo
|
107
|
+
return info if Bizside.rails_env&.test?
|
108
|
+
|
109
|
+
logger.record(info)
|
110
|
+
|
111
|
+
info
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
|
116
|
+
def logger
|
117
|
+
@logger ||= Bizside::Audit::JobLogger.logger
|
118
|
+
end
|
119
|
+
|
120
|
+
def build_loginfo
|
121
|
+
info = {
|
122
|
+
time: Time.now.strftime('%Y-%m-%dT%H:%M:%S.%3N%z'),
|
123
|
+
add_on_name: Bizside.config.add_on_name,
|
124
|
+
server_address: hostname,
|
125
|
+
class: payload['class'],
|
126
|
+
args: payload['args'].to_s,
|
127
|
+
queue: queue,
|
128
|
+
worker: worker.to_s,
|
129
|
+
exception: exception.class,
|
130
|
+
exception_message: exception.to_s,
|
131
|
+
exception_backtrace: Array(exception.backtrace)[0..10].join("\n") # Get only the top 10 because there are many traces.
|
132
|
+
}
|
133
|
+
info
|
134
|
+
end
|
135
|
+
|
136
|
+
# ホスト名を取得。
|
137
|
+
#
|
138
|
+
# 下記理由から hostname(1) を使用:
|
139
|
+
#
|
140
|
+
# * job 実行環境では環境変数 HOSTNAME がセットされていないケースがある
|
141
|
+
# (例: 通常の god 起動の場合。他方、container 起動の場合は
|
142
|
+
# HOSTNAME がセットされている模様)。
|
143
|
+
# * hostname(1) は Linux Standard Base 共通コマンドのため必ず存在する。
|
144
|
+
def hostname
|
145
|
+
@hostname ||= (`hostname`.chomp rescue '(unknown)')
|
146
|
+
end
|
147
|
+
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
Resque::Failure::Multiple.configure do |multi|
|
153
|
+
multi.classes = [Resque::Failure::Redis, Resque::Failure::LogOutput, Resque::Failure::JobAuditLog]
|
154
|
+
end
|
data/lib/bizside/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bizside
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.
|
4
|
+
version: 2.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- bizside-developers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-03-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -419,6 +419,8 @@ files:
|
|
419
419
|
- lib/bizside/railtie.rb
|
420
420
|
- lib/bizside/record_has_warnings.rb
|
421
421
|
- lib/bizside/resque.rb
|
422
|
+
- lib/bizside/resque.rb.bkp
|
423
|
+
- lib/bizside/resque.rb~
|
422
424
|
- lib/bizside/rsync.rb
|
423
425
|
- lib/bizside/safe_pty.rb
|
424
426
|
- lib/bizside/shib_utils.rb
|
@@ -441,6 +443,7 @@ files:
|
|
441
443
|
- lib/bizside/user_agent/controller_helper.rb
|
442
444
|
- lib/bizside/validations.rb
|
443
445
|
- lib/bizside/version.rb
|
446
|
+
- lib/bizside/version.rb~
|
444
447
|
- lib/bizside/view_helper.rb
|
445
448
|
- lib/bizside/warning.rb
|
446
449
|
- lib/bizside/yes.rb
|
@@ -479,7 +482,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
479
482
|
- !ruby/object:Gem::Version
|
480
483
|
version: '0'
|
481
484
|
requirements: []
|
482
|
-
rubygems_version: 3.2.
|
485
|
+
rubygems_version: 3.2.29
|
483
486
|
signing_key:
|
484
487
|
specification_version: 4
|
485
488
|
summary: Bizside is an utilities for web application.
|