rbatch 2.0.0 → 2.1.0
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.
- data/CHANGELOG +7 -0
- data/README.ja.md +70 -47
- data/README.md +261 -238
- data/bin/rbatch-init +27 -6
- data/doc/RBatch/CommonConfig.html +108 -12
- data/doc/RBatch/Config.html +108 -12
- data/doc/RBatch/Log.html +108 -65
- data/doc/RBatch/RunConf.html +78 -78
- data/doc/RBatch.html +274 -44
- data/doc/created.rid +9 -9
- data/doc/index.html +30 -8
- data/doc/lib/rbatch/cmd_rb.html +1 -1
- data/doc/lib/rbatch/common_config_rb.html +1 -1
- data/doc/lib/rbatch/config_rb.html +1 -1
- data/doc/lib/rbatch/double_run_checker_rb.html +1 -1
- data/doc/lib/rbatch/log_rb.html +1 -1
- data/doc/lib/rbatch/run_conf_rb.html +1 -1
- data/doc/lib/rbatch/version_rb.html +1 -1
- data/doc/lib/rbatch_rb.html +1 -1
- data/lib/rbatch/common_config.rb +36 -10
- data/lib/rbatch/config.rb +36 -10
- data/lib/rbatch/log.rb +12 -1
- data/lib/rbatch/run_conf.rb +4 -1
- data/lib/rbatch/version.rb +1 -1
- data/lib/rbatch.rb +68 -14
- data/sample/.rbatchrc +127 -0
- data/spec/cmd_spec.rb +2 -4
- data/spec/common_config_spec.rb +38 -7
- data/spec/config_spec.rb +36 -6
- data/spec/log_spec.rb +6 -6
- data/spec/rbatch_spec.rb +2 -4
- data/spec/run_conf_spec.rb +3 -2
- data/spec/spec_helper.rb +5 -0
- metadata +5 -3
- data/sample/conf/rbatch.yaml +0 -68
data/doc/lib/rbatch_rb.html
CHANGED
data/lib/rbatch/common_config.rb
CHANGED
@@ -4,10 +4,6 @@ require 'pathname'
|
|
4
4
|
module RBatch
|
5
5
|
|
6
6
|
module_function
|
7
|
-
|
8
|
-
# Alias of RBatch::CommonConfig.new
|
9
|
-
def common_config ; CommonConfig.new end
|
10
|
-
|
11
7
|
# Common-config Reader
|
12
8
|
#
|
13
9
|
# Read common config file and return hash opject. If the key does not exist in config file, raise RBatch::CommonConfig::Exception.
|
@@ -26,18 +22,48 @@ module RBatch
|
|
26
22
|
# => {"key" => "value", "array" => ["item1", "item2", "item3"]}
|
27
23
|
class CommonConfig
|
28
24
|
@path
|
29
|
-
@
|
25
|
+
@hash
|
30
26
|
def initialize
|
31
27
|
file = RBatch.run_conf[:common_conf_name]
|
32
|
-
@path = File.join(RBatch.
|
33
|
-
|
28
|
+
@path = File.join(RBatch.conf_dir,file)
|
29
|
+
begin
|
30
|
+
@hash = YAML::load_file(@path)
|
31
|
+
rescue Errno::ENOENT => e
|
32
|
+
@hash = nil
|
33
|
+
end
|
34
34
|
end
|
35
35
|
def[](key)
|
36
|
-
|
37
|
-
|
36
|
+
if @hash.nil?
|
37
|
+
raise RBatch::CommonConfig::Exception, "Common Config file \"#{@path}\" does not exist"
|
38
|
+
end
|
39
|
+
if @hash[key].nil?
|
40
|
+
if key.class == Symbol
|
41
|
+
raise RBatch::CommonConfig::Exception, "Value of key(:#{key} (Symbol)) is nil. By any chance, dou you mistake key class Symbol for String?"
|
42
|
+
elsif key.class == String
|
43
|
+
raise RBatch::CommonConfig::Exception, "Value of key(\"#{key}\" (String)) is nil"
|
44
|
+
else
|
45
|
+
raise RBatch::CommonConfig::Exception, "Value of key(#{key}) is nil"
|
46
|
+
end
|
47
|
+
else
|
48
|
+
@hash[key]
|
49
|
+
end
|
38
50
|
end
|
39
51
|
def path ; @path ; end
|
40
|
-
def
|
52
|
+
def exist? ; ! @hash.nil? ; end
|
53
|
+
def to_h
|
54
|
+
if @hash.nil?
|
55
|
+
raise RBatch::CommonConfig::Exception, "Common Config file \"#{@path}\" does not exist"
|
56
|
+
else
|
57
|
+
@hash
|
58
|
+
end
|
59
|
+
end
|
60
|
+
def to_s
|
61
|
+
if @hash.nil?
|
62
|
+
raise RBatch::CommonConfig::Exception, "Common Config file \"#{@path}\" does not exist"
|
63
|
+
else
|
64
|
+
@hash.to_s
|
65
|
+
end
|
66
|
+
end
|
41
67
|
end
|
42
68
|
|
43
69
|
class RBatch::CommonConfig::Exception < Exception; end
|
data/lib/rbatch/config.rb
CHANGED
@@ -4,10 +4,6 @@ require 'pathname'
|
|
4
4
|
module RBatch
|
5
5
|
|
6
6
|
module_function
|
7
|
-
|
8
|
-
# Alias of RBatch::Config.new
|
9
|
-
def config ; Config.new end
|
10
|
-
|
11
7
|
# Config Reader
|
12
8
|
#
|
13
9
|
# Read config file and return hash opject. If the key does not exist in config file, raise RBatch::Config::Exception.
|
@@ -27,18 +23,48 @@ module RBatch
|
|
27
23
|
# => {"key" => "value", "array" => ["item1", "item2", "item3"]}
|
28
24
|
class Config
|
29
25
|
@path
|
30
|
-
@
|
26
|
+
@hash
|
31
27
|
def initialize
|
32
28
|
file = Pathname(File.basename(RBatch.program_name)).sub_ext(".yaml").to_s
|
33
|
-
@path = File.join(RBatch.
|
34
|
-
|
29
|
+
@path = File.join(RBatch.conf_dir,file)
|
30
|
+
begin
|
31
|
+
@hash = YAML::load_file(@path)
|
32
|
+
rescue Errno::ENOENT => e
|
33
|
+
@hash = nil
|
34
|
+
end
|
35
35
|
end
|
36
36
|
def[](key)
|
37
|
-
|
38
|
-
|
37
|
+
if @hash.nil?
|
38
|
+
raise RBatch::Config::Exception, "Config file \"#{@path}\" does not exist"
|
39
|
+
end
|
40
|
+
if @hash[key].nil?
|
41
|
+
if key.class == Symbol
|
42
|
+
raise RBatch::Config::Exception, "Value of key(:#{key} (Symbol)) is nil. By any chance, dou you mistake key class Symbol for String?"
|
43
|
+
elsif key.class == String
|
44
|
+
raise RBatch::Config::Exception, "Value of key(\"#{key}\" (String)) is nil"
|
45
|
+
else
|
46
|
+
raise RBatch::Config::Exception, "Value of key(#{key}) is nil."
|
47
|
+
end
|
48
|
+
else
|
49
|
+
@hash[key]
|
50
|
+
end
|
39
51
|
end
|
40
52
|
def path ; @path ; end
|
41
|
-
def
|
53
|
+
def exist? ; ! @hash.nil? ; end
|
54
|
+
def to_h
|
55
|
+
if @hash.nil?
|
56
|
+
raise RBatch::Config::Exception, "Config file \"#{@path}\" does not exist"
|
57
|
+
else
|
58
|
+
@hash
|
59
|
+
end
|
60
|
+
end
|
61
|
+
def to_s
|
62
|
+
if @hash.nil?
|
63
|
+
raise RBatch::Config::Exception, "Config file \"#{@path}\" does not exist"
|
64
|
+
else
|
65
|
+
@hash.to_s
|
66
|
+
end
|
67
|
+
end
|
42
68
|
end
|
43
69
|
|
44
70
|
class RBatch::Config::Exception < Exception; end
|
data/lib/rbatch/log.rb
CHANGED
@@ -126,9 +126,16 @@ module RBatch
|
|
126
126
|
@stdout_log.level = @@log_level_map[@opt[:log_level]]
|
127
127
|
@stdout_log.formatter = formatter
|
128
128
|
end
|
129
|
-
RBatch.journal :info,"Start Logging
|
129
|
+
RBatch.journal :info,"Start Logging: \"#{path}\""
|
130
130
|
# delete old log
|
131
131
|
self.delete_old_log(@opt[:log_delete_old_log_date]) if @opt[:log_delete_old_log]
|
132
|
+
# Firstly write journal to log
|
133
|
+
if RBatch.run_conf[:mix_rbatch_msg_to_log]
|
134
|
+
RBatch.journals.each do |str|
|
135
|
+
self.journal(str)
|
136
|
+
end
|
137
|
+
RBatch.add_log(self)
|
138
|
+
end
|
132
139
|
# Start logging
|
133
140
|
if block_given?
|
134
141
|
begin
|
@@ -170,6 +177,10 @@ module RBatch
|
|
170
177
|
@log.debug(a)
|
171
178
|
end
|
172
179
|
|
180
|
+
def journal(a)
|
181
|
+
@log.info(a)
|
182
|
+
end
|
183
|
+
|
173
184
|
def close
|
174
185
|
@stdout_log.close if @opt[:log_stdout]
|
175
186
|
@log.close
|
data/lib/rbatch/run_conf.rb
CHANGED
@@ -8,6 +8,8 @@ module RBatch
|
|
8
8
|
@@def_opt = {
|
9
9
|
:conf_dir => "<home>/conf",
|
10
10
|
:common_conf_name => "common.yaml",
|
11
|
+
:lib_dir => "<home>/lib",
|
12
|
+
:auto_lib_load => true,
|
11
13
|
:forbid_double_run => false,
|
12
14
|
:cmd_raise => false,
|
13
15
|
:cmd_timeout => 0,
|
@@ -23,7 +25,8 @@ module RBatch
|
|
23
25
|
:log_mail_to => nil,
|
24
26
|
:log_mail_from => "rbatch.localhost",
|
25
27
|
:log_mail_server_host => "localhost",
|
26
|
-
:log_mail_server_port => 25
|
28
|
+
:log_mail_server_port => 25,
|
29
|
+
:mix_rbatch_msg_to_log => true
|
27
30
|
}
|
28
31
|
def initialize(run_conf_path,home_dir)
|
29
32
|
@run_conf_path = run_conf_path
|
data/lib/rbatch/version.rb
CHANGED
data/lib/rbatch.rb
CHANGED
@@ -2,54 +2,108 @@ $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__)))
|
|
2
2
|
require 'yaml'
|
3
3
|
|
4
4
|
module RBatch
|
5
|
-
@@program_name =
|
6
|
-
@@program_base =
|
5
|
+
@@program_name = nil
|
6
|
+
@@program_base = nil
|
7
|
+
@@program_path = nil
|
7
8
|
@@home_dir = nil
|
8
9
|
@@run_conf_path = nil
|
10
|
+
@@run_conf_fpath = nil
|
9
11
|
@@run_conf = nil
|
12
|
+
@@config = nil
|
13
|
+
@@common_config = nil
|
10
14
|
@@journal_verbose = 3
|
11
15
|
@@journal_verbose_map = { :error => 1, :warn => 2, :info => 3, :debug => 4}
|
16
|
+
@@journals = []
|
17
|
+
@@logs = []
|
12
18
|
module_function
|
13
19
|
def program_name ; @@program_name ; end
|
14
20
|
def program_base ; @@program_base ; end
|
21
|
+
def program_path ; @@program_path ; end
|
15
22
|
def home_dir ; @@home_dir ; end
|
16
23
|
def run_conf_path ; @@run_conf_path ; end
|
17
24
|
def run_conf ; @@run_conf ; end
|
18
25
|
def conf_dir ; @@run_conf[:conf_dir].gsub("<home>",@@home_dir) ; end
|
19
26
|
def log_dir ; @@run_conf[:log_dir].gsub("<home>",@@home_dir) ; end
|
27
|
+
def lib_dir ; @@run_conf[:lib_dir].gsub("<home>",@@home_dir) ; end
|
28
|
+
def config ; @@config ; end
|
29
|
+
def common_config ; @@common_config ; end
|
30
|
+
def journals ; @@journals ; end
|
31
|
+
def add_log(log)
|
32
|
+
@@logs << log
|
33
|
+
end
|
20
34
|
def journal(level,str)
|
21
|
-
|
35
|
+
if @@journal_verbose_map[level] <= @@journal_verbose
|
36
|
+
str = "[RBatch] " + str
|
37
|
+
puts str
|
38
|
+
@@journals << str
|
39
|
+
@@logs.each do |log|
|
40
|
+
if RBatch.run_conf[:mix_rbatch_msg_to_log]
|
41
|
+
log.journal(str)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
22
45
|
end
|
23
46
|
def init
|
24
47
|
@@journal_verbose = ENV["RB_VERBOSE"].to_i if ENV["RB_VERBOSE"]
|
48
|
+
RBatch.journal :info,"=== START RBatch === (PID=#{$$.to_s})"
|
49
|
+
@@program_name = $PROGRAM_NAME
|
50
|
+
@@program_base = File.basename($PROGRAM_NAME)
|
51
|
+
@@program_path = File.expand_path(@@program_name)
|
25
52
|
if ENV["RB_HOME"]
|
26
|
-
@@home_dir = ENV["RB_HOME"]
|
27
|
-
RBatch.journal :
|
53
|
+
@@home_dir = File.expand_path(ENV["RB_HOME"])
|
54
|
+
RBatch.journal :debug,"RB_HOME : \"#{@@home_dir}\" (defined by $RB_HOME)"
|
28
55
|
else
|
29
|
-
@@home_dir = File.join(File.dirname(@@program_name) , "..")
|
30
|
-
RBatch.journal :
|
56
|
+
@@home_dir = File.expand_path(File.join(File.dirname(@@program_name) , ".."))
|
57
|
+
RBatch.journal :debug,"RB_HOME : \"#{@@home_dir}\" (default)"
|
31
58
|
end
|
32
59
|
@@run_conf_path = File.join(@@home_dir,".rbatchrc")
|
33
|
-
RBatch.journal :info,"Run-Conf: \"#{@@run_conf_path}\""
|
34
|
-
|
60
|
+
RBatch.journal :info,"Load Run-Conf: \"#{@@run_conf_path}\""
|
35
61
|
@@run_conf = RunConf.new(@@run_conf_path,@@home_dir)
|
36
62
|
RBatch.journal :debug,"RBatch option : #{@@run_conf.inspect}"
|
63
|
+
@@common_config = RBatch::CommonConfig.new
|
64
|
+
RBatch.journal :info,"Load Config : \"#{@@common_config.path}\"" if @@common_config.exist?
|
65
|
+
@@config = RBatch::Config.new
|
66
|
+
RBatch.journal :info,"Load Config : \"#{@@config.path}\"" if @@config.exist?
|
67
|
+
end
|
68
|
+
def reload_config
|
69
|
+
begin
|
70
|
+
@@config = RBatch::Config.new
|
71
|
+
RBatch.journal :info, "Load Config : \"#{@@config.path}\""
|
72
|
+
rescue Errno::ENOENT => e
|
73
|
+
end
|
74
|
+
end
|
75
|
+
def reload_common_config
|
76
|
+
begin
|
77
|
+
@@common_config = RBatch::CommonConfig.new
|
78
|
+
RBatch.journal :info,"Load Config : \"#{@@common_config.path}\""
|
79
|
+
rescue Errno::ENOENT => e
|
80
|
+
end
|
37
81
|
end
|
38
82
|
end
|
39
83
|
|
40
84
|
# main
|
41
85
|
require 'rbatch/run_conf'
|
42
86
|
require 'rbatch/double_run_checker'
|
87
|
+
require 'rbatch/log'
|
88
|
+
require 'rbatch/config'
|
89
|
+
require 'rbatch/common_config'
|
90
|
+
require 'rbatch/cmd'
|
43
91
|
|
44
92
|
RBatch::init
|
93
|
+
|
45
94
|
if ( RBatch.run_conf[:forbid_double_run] )
|
46
95
|
RBatch::DoubleRunChecker.check(File.basename(RBatch.program_name)) #raise error if check is NG
|
47
96
|
RBatch::DoubleRunChecker.make_lock_file(File.basename(RBatch.program_name))
|
48
97
|
end
|
49
98
|
|
50
|
-
require 'rbatch/log'
|
51
|
-
require 'rbatch/config'
|
52
|
-
require 'rbatch/common_config'
|
53
|
-
require 'rbatch/cmd'
|
54
99
|
|
55
|
-
|
100
|
+
|
101
|
+
if RBatch.run_conf[:auto_lib_load] && Dir.exist?(RBatch.lib_dir)
|
102
|
+
Dir::foreach(RBatch.lib_dir) do |file|
|
103
|
+
if /.*rb/ =~ file
|
104
|
+
require File.join(RBatch.lib_dir,File.basename(file,".rb"))
|
105
|
+
RBatch.journal :info, "Load Library : \"#{File.join(RBatch.lib_dir,file)}\" "
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
RBatch.journal :info,"Start Script : \"#{RBatch.program_path}\""
|
data/sample/.rbatchrc
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# RBatch Run-Conf (.rbatchrc)
|
2
|
+
#
|
3
|
+
# This format is YAML.
|
4
|
+
#
|
5
|
+
|
6
|
+
# -------------------
|
7
|
+
# Global setting
|
8
|
+
# -------------------
|
9
|
+
|
10
|
+
# Conf Directory
|
11
|
+
#
|
12
|
+
# Default is "<home>/conf"
|
13
|
+
#
|
14
|
+
# <home> is replaced to ${RB_HOME}
|
15
|
+
#
|
16
|
+
#conf_dir: <home>/config
|
17
|
+
#conf_dir: /etc/rbatch/
|
18
|
+
|
19
|
+
# Common config file name
|
20
|
+
#
|
21
|
+
# Default is "common.yaml"
|
22
|
+
#
|
23
|
+
#common_conf_name: share.yaml
|
24
|
+
|
25
|
+
# Forbit Script Double Run
|
26
|
+
#
|
27
|
+
# Default is false.
|
28
|
+
# If true, two same name scripts cannot run at the same time.
|
29
|
+
#
|
30
|
+
#forbid_double_run: true
|
31
|
+
#forbid_double_run: false
|
32
|
+
|
33
|
+
# -------------------
|
34
|
+
# Cmd setting
|
35
|
+
# -------------------
|
36
|
+
|
37
|
+
# Raise Exception
|
38
|
+
#
|
39
|
+
# Default is false.
|
40
|
+
# If true, when command exit status is not 0, raise exception.
|
41
|
+
#
|
42
|
+
#cmd_raise : true
|
43
|
+
#cmd_raise : false
|
44
|
+
|
45
|
+
# Command Timeout
|
46
|
+
#
|
47
|
+
# Default is 0 [sec].
|
48
|
+
#
|
49
|
+
#cmd_timeout: 5
|
50
|
+
|
51
|
+
# -------------------
|
52
|
+
# Log setting
|
53
|
+
# -------------------
|
54
|
+
|
55
|
+
# Log Directory
|
56
|
+
#
|
57
|
+
# Default is "<home>/log"
|
58
|
+
# <home> is replaced to ${RB_HOME}
|
59
|
+
#
|
60
|
+
#log_dir: <home>/rb_log
|
61
|
+
#log_dir: /var/log/rbatch/
|
62
|
+
|
63
|
+
# Log File Name
|
64
|
+
#
|
65
|
+
# Default is "<date>_<time>_<prog>.log".
|
66
|
+
# <data> is replaced to YYYYMMDD date string
|
67
|
+
# <time> is replaced to HHMMSS time string
|
68
|
+
# <prog> is replaced to Program file base name (except extention).
|
69
|
+
# <host> is replaced to Hostname.
|
70
|
+
#
|
71
|
+
#log_name : "<date>_<time>_<prog>.log"
|
72
|
+
#log_name : "<date>_<prog>.log"
|
73
|
+
|
74
|
+
# Append log or not
|
75
|
+
#
|
76
|
+
# Default is ture.
|
77
|
+
#
|
78
|
+
#log_append : true
|
79
|
+
#log_append : false
|
80
|
+
|
81
|
+
# Log Level
|
82
|
+
#
|
83
|
+
# Default is "info".
|
84
|
+
# Effective values are "debug","info","wran","error",and "fatal".
|
85
|
+
#
|
86
|
+
#log_level : "debug"
|
87
|
+
#log_level : "info"
|
88
|
+
#log_level : "warn"
|
89
|
+
#log_level : "error"
|
90
|
+
#log_level : "fatal"
|
91
|
+
|
92
|
+
# Print log string both file and STDOUT
|
93
|
+
#
|
94
|
+
# Default is false.
|
95
|
+
#
|
96
|
+
#log_stdout : true
|
97
|
+
#log_stdout : false
|
98
|
+
|
99
|
+
# Delete old log files
|
100
|
+
#
|
101
|
+
# Default is false.
|
102
|
+
# If this is true, delete old log file when RBatch::Log.new is called.
|
103
|
+
# A log file to delete is a log file which was made by the RBatch::Log instance,
|
104
|
+
# and log filename format include "<date>".
|
105
|
+
#
|
106
|
+
#log_delete_old_log: true
|
107
|
+
#log_delete_old_log: false
|
108
|
+
|
109
|
+
# The day of leaving log files
|
110
|
+
#
|
111
|
+
# Default is 7.
|
112
|
+
#
|
113
|
+
#log_delete_old_log_date: 14
|
114
|
+
|
115
|
+
# Send mail or not
|
116
|
+
#
|
117
|
+
# Default is false.
|
118
|
+
# When log.error(msg) or log.fatal(msg) called , send e-mail including "msg".
|
119
|
+
#
|
120
|
+
#log_send_mail : true
|
121
|
+
|
122
|
+
# Mail parameters
|
123
|
+
#
|
124
|
+
#log_mail_to : "xxx@sample.com"
|
125
|
+
#log_mail_from : "xxx@sample.com"
|
126
|
+
#log_mail_server_host : "localhost"
|
127
|
+
#log_mail_server_port : 25
|
data/spec/cmd_spec.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require '
|
2
|
-
ENV["RB_VERBOSE"]="0"
|
3
|
-
ENV["RB_HOME"]=Dir.tmpdir
|
1
|
+
require File.expand_path(File.join( File.dirname(__FILE__), 'spec_helper'))
|
4
2
|
|
5
3
|
require 'rbatch'
|
6
4
|
|
@@ -109,7 +107,7 @@ describe RBatch::Cmd do
|
|
109
107
|
|
110
108
|
describe "option by config" do
|
111
109
|
before :all do
|
112
|
-
@config_dir=File.join(
|
110
|
+
@config_dir=File.join(ENV["RB_HOME"],"conf")
|
113
111
|
@config_file = File.join(@config_dir , "rbatch.yaml")
|
114
112
|
Dir::mkdir @config_dir if ! Dir.exists? @config_dir
|
115
113
|
end
|
data/spec/common_config_spec.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
require '
|
2
|
-
ENV["RB_VERBOSE"]="0"
|
3
|
-
ENV["RB_HOME"]=Dir.tmpdir
|
1
|
+
require File.expand_path(File.join( File.dirname(__FILE__), 'spec_helper'))
|
4
2
|
|
5
3
|
require 'rbatch'
|
6
4
|
|
7
5
|
describe RBatch::CommonConfig do
|
8
6
|
before :all do
|
9
|
-
@config_dir=File.join(
|
7
|
+
@config_dir=File.join(ENV["RB_HOME"],"conf")
|
10
8
|
@config_file = File.join(@config_dir , "common.yaml")
|
11
9
|
Dir::mkdir @config_dir if ! Dir.exists? @config_dir
|
12
10
|
end
|
@@ -23,32 +21,65 @@ describe RBatch::CommonConfig do
|
|
23
21
|
|
24
22
|
it "read config" do
|
25
23
|
open( @config_file , "w" ){|f| f.write("key: value")}
|
24
|
+
RBatch.reload_common_config
|
26
25
|
expect(RBatch.common_config["key"]).to eq "value"
|
27
26
|
end
|
28
27
|
|
28
|
+
it "read config. Key is Symbol" do
|
29
|
+
open( @config_file , "w" ){|f| f.write(":key: value")}
|
30
|
+
RBatch.reload_common_config
|
31
|
+
expect(RBatch.common_config[:key]).to eq "value"
|
32
|
+
end
|
33
|
+
|
29
34
|
it "raise error when config does not exist" do
|
35
|
+
RBatch.reload_common_config
|
36
|
+
expect {
|
37
|
+
RBatch.common_config["hoge"]
|
38
|
+
}.to raise_error(RBatch::CommonConfig::Exception)
|
30
39
|
expect {
|
31
|
-
RBatch.common_config
|
32
|
-
}.to raise_error(
|
40
|
+
RBatch.common_config.to_h
|
41
|
+
}.to raise_error(RBatch::CommonConfig::Exception)
|
42
|
+
expect {
|
43
|
+
RBatch.common_config.to_s
|
44
|
+
}.to raise_error(RBatch::CommonConfig::Exception)
|
33
45
|
end
|
34
46
|
|
35
47
|
it "read config twice" do
|
36
48
|
open( @config_file , "w" ){|f| f.write("key: value")}
|
49
|
+
RBatch.reload_common_config
|
37
50
|
expect(RBatch.common_config["key"]).to eq "value"
|
38
51
|
expect(RBatch.common_config["key"]).to eq "value"
|
39
52
|
end
|
40
53
|
|
41
54
|
it "raise error when read value which key does not exist" do
|
42
55
|
open( @config_file , "w" ){|f| f.write("key: value")}
|
56
|
+
RBatch.reload_common_config
|
43
57
|
expect {
|
44
58
|
RBatch.common_config["not_exist"]
|
45
59
|
}.to raise_error(RBatch::CommonConfig::Exception)
|
46
60
|
end
|
47
61
|
|
62
|
+
it "raise error when read value which key mistake String for Symbol" do
|
63
|
+
open( @config_file , "w" ){|f| f.write(":key: value")}
|
64
|
+
RBatch.reload_common_config
|
65
|
+
expect {
|
66
|
+
RBatch.common_config["key"]
|
67
|
+
}.to raise_error(RBatch::CommonConfig::Exception)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "raise error when read value which key mistake Symbol for String" do
|
71
|
+
open( @config_file , "w" ){|f| f.write("key: value")}
|
72
|
+
RBatch.reload_common_config
|
73
|
+
expect {
|
74
|
+
RBatch.common_config[:key]
|
75
|
+
}.to raise_error(RBatch::CommonConfig::Exception)
|
76
|
+
end
|
77
|
+
|
48
78
|
it "success when common_conf_name changed" do
|
49
|
-
conf=File.join(
|
79
|
+
conf=File.join(RBatch.conf_dir,"global.yaml")
|
50
80
|
open( conf , "w" ){|f| f.write("key4: value4")}
|
51
81
|
RBatch.run_conf[:common_conf_name]="global.yaml"
|
82
|
+
RBatch.reload_common_config
|
52
83
|
expect(RBatch.common_config["key4"]).to eq "value4"
|
53
84
|
end
|
54
85
|
end
|
data/spec/config_spec.rb
CHANGED
@@ -1,12 +1,10 @@
|
|
1
|
-
require '
|
2
|
-
ENV["RB_VERBOSE"]="0"
|
3
|
-
ENV["RB_HOME"]=Dir.tmpdir
|
1
|
+
require File.expand_path(File.join( File.dirname(__FILE__), 'spec_helper'))
|
4
2
|
|
5
3
|
require 'rbatch'
|
6
4
|
|
7
5
|
describe RBatch::Config do
|
8
6
|
before :all do
|
9
|
-
@config_dir=File.join(
|
7
|
+
@config_dir=File.join(ENV["RB_HOME"],"conf")
|
10
8
|
@config_file = File.join(@config_dir , "rspec.yaml")
|
11
9
|
Dir::mkdir @config_dir if ! Dir.exists? @config_dir
|
12
10
|
end
|
@@ -23,27 +21,59 @@ describe RBatch::Config do
|
|
23
21
|
|
24
22
|
it "read config" do
|
25
23
|
open( @config_file , "w" ){|f| f.write("key: value")}
|
24
|
+
RBatch.reload_config
|
26
25
|
expect(RBatch.config["key"]).to eq "value"
|
27
26
|
end
|
28
27
|
|
28
|
+
it "read config. Key is Symbol" do
|
29
|
+
open( @config_file , "w" ){|f| f.write(":key: value")}
|
30
|
+
RBatch.reload_config
|
31
|
+
expect(RBatch.config[:key]).to eq "value"
|
32
|
+
end
|
33
|
+
|
29
34
|
it "raise error when config does not exist" do
|
35
|
+
RBatch.reload_config
|
36
|
+
expect {
|
37
|
+
RBatch.config["hoge"]
|
38
|
+
}.to raise_error(RBatch::Config::Exception)
|
30
39
|
expect {
|
31
|
-
RBatch.config
|
32
|
-
}.to raise_error(
|
40
|
+
RBatch.config.to_h
|
41
|
+
}.to raise_error(RBatch::Config::Exception)
|
42
|
+
expect {
|
43
|
+
RBatch.config.to_s
|
44
|
+
}.to raise_error(RBatch::Config::Exception)
|
33
45
|
end
|
34
46
|
|
35
47
|
it "read config twice" do
|
36
48
|
open( @config_file , "w" ){|f| f.write("key: value")}
|
49
|
+
RBatch.reload_config
|
37
50
|
expect(RBatch.config["key"]).to eq "value"
|
38
51
|
expect(RBatch.config["key"]).to eq "value"
|
39
52
|
end
|
40
53
|
|
41
54
|
it "raise error when read value which key does not exist" do
|
42
55
|
open( @config_file , "w" ){|f| f.write("key: value")}
|
56
|
+
RBatch.reload_config
|
43
57
|
expect {
|
44
58
|
RBatch.config["not_exist"]
|
45
59
|
}.to raise_error(RBatch::Config::Exception)
|
46
60
|
end
|
47
61
|
|
62
|
+
it "raise error when read value which key mistake String for Symbol" do
|
63
|
+
open( @config_file , "w" ){|f| f.write("key: value")}
|
64
|
+
RBatch.reload_config
|
65
|
+
expect {
|
66
|
+
RBatch.config[:key]
|
67
|
+
}.to raise_error(RBatch::Config::Exception)
|
68
|
+
end
|
69
|
+
|
70
|
+
it "raise error when read value which key mistake Symbol for String" do
|
71
|
+
open( @config_file , "w" ){|f| f.write(":key: value")}
|
72
|
+
RBatch.reload_config
|
73
|
+
expect {
|
74
|
+
RBatch.config["key"]
|
75
|
+
}.to raise_error(RBatch::Config::Exception)
|
76
|
+
end
|
77
|
+
|
48
78
|
|
49
79
|
end
|
data/spec/log_spec.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
require '
|
2
|
-
ENV["RB_VERBOSE"]="0"
|
3
|
-
ENV["RB_HOME"]=Dir.tmpdir
|
1
|
+
require File.expand_path(File.join( File.dirname(__FILE__), 'spec_helper'))
|
4
2
|
|
5
3
|
require 'rbatch'
|
6
4
|
|
7
5
|
describe RBatch::Log do
|
8
6
|
|
9
7
|
before :all do
|
10
|
-
@dir = File.join(
|
8
|
+
@dir = File.join(ENV["RB_HOME"],"log")
|
11
9
|
Dir::mkdir(@dir)if ! Dir.exists? @dir
|
12
10
|
end
|
13
11
|
|
@@ -84,7 +82,8 @@ describe RBatch::Log do
|
|
84
82
|
end
|
85
83
|
|
86
84
|
it "change log dir" do
|
87
|
-
@tmp =
|
85
|
+
@tmp = File.join(ENV["RB_HOME"],"log3")
|
86
|
+
Dir.mkdir(@tmp)
|
88
87
|
RBatch::Log.new({:name => "c.log", :dir=> @tmp }) do | log |
|
89
88
|
log.info("hoge")
|
90
89
|
end
|
@@ -282,7 +281,8 @@ describe RBatch::Log do
|
|
282
281
|
end
|
283
282
|
|
284
283
|
it "change log dir" do
|
285
|
-
@tmp =
|
284
|
+
@tmp = File.join(ENV["RB_HOME"],"log2")
|
285
|
+
Dir.mkdir(@tmp)
|
286
286
|
confstr = "log_name: c.log\nlog_dir: " + @tmp
|
287
287
|
open( RBatch.run_conf_path , "a" ){|f| f.write(confstr)}
|
288
288
|
RBatch.run_conf.reload
|