batchbase 0.0.5 → 0.0.6
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/lib/batchbase/core.rb +4 -4
- data/lib/batchbase/version.rb +1 -1
- data/test/batch_signal_other_class.rb +27 -0
- data/test/test.rb +20 -0
- metadata +5 -2
data/lib/batchbase/core.rb
CHANGED
@@ -136,7 +136,7 @@ module Batchbase
|
|
136
136
|
@__signal_observers ||= []
|
137
137
|
end
|
138
138
|
|
139
|
-
def set_signal_observer(method_name)
|
139
|
+
def set_signal_observer(method_name,object=self)
|
140
140
|
@__signal_observers ||= []
|
141
141
|
case method_name
|
142
142
|
when String
|
@@ -145,7 +145,7 @@ module Batchbase
|
|
145
145
|
else
|
146
146
|
raise ArgumentError.new('method_name must be String or Symbol')
|
147
147
|
end
|
148
|
-
@__signal_observers << method_name
|
148
|
+
@__signal_observers << [object,method_name]
|
149
149
|
end
|
150
150
|
|
151
151
|
def parse_options(options,argv=ARGV)
|
@@ -277,9 +277,9 @@ module Batchbase
|
|
277
277
|
#
|
278
278
|
def r_signal(signal)
|
279
279
|
sent_signal = false
|
280
|
-
signal_observers.each do |
|
280
|
+
signal_observers.each do |ar|
|
281
281
|
begin
|
282
|
-
|
282
|
+
ar[0].send ar[1],signal
|
283
283
|
sent_signal = true
|
284
284
|
rescue => e
|
285
285
|
message = "signal #{signal} received. but can not call '#{method_name}'"
|
data/lib/batchbase/version.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
class BatchSignalOtherClass
|
2
|
+
include Batchbase::Core
|
3
|
+
skip_logging
|
4
|
+
|
5
|
+
def initialize
|
6
|
+
end
|
7
|
+
|
8
|
+
TEST_FILE = '/tmp/.batchbase_batch.txt'
|
9
|
+
|
10
|
+
def proceed(opt={})
|
11
|
+
@shutdown = false
|
12
|
+
sc = SomeClass.new
|
13
|
+
set_signal_observer(:r_sig,sc)
|
14
|
+
set_signal_observer(:receive_signal)
|
15
|
+
|
16
|
+
execute(opt) do
|
17
|
+
sleep 4
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
class SomeClass
|
23
|
+
RECEIVE_SIGNAL_FILE = '/tmp/.batchbase_test.receive_signal.pid'
|
24
|
+
def r_sig(sig)
|
25
|
+
File.write(RECEIVE_SIGNAL_FILE,$$)
|
26
|
+
end
|
27
|
+
end
|
data/test/test.rb
CHANGED
@@ -11,6 +11,7 @@ require 'Fileutils'
|
|
11
11
|
|
12
12
|
require 'batch'
|
13
13
|
require 'batch_too_long'
|
14
|
+
require 'batch_signal_other_class'
|
14
15
|
|
15
16
|
class TestBatchbase < Test::Unit::TestCase
|
16
17
|
|
@@ -18,6 +19,7 @@ class TestBatchbase < Test::Unit::TestCase
|
|
18
19
|
PID_FILE_DAEMONIZE_TEST = '/tmp/.batchbase_daemonize_test.pid'
|
19
20
|
LOG_FILE = '/tmp/batchbase_test.log'
|
20
21
|
PROCESS_NAME = 'batchbase_test_hogehoge'
|
22
|
+
RECEIVE_SIGNAL_FILE = '/tmp/.batchbase_test.receive_signal.pid'
|
21
23
|
|
22
24
|
def setup
|
23
25
|
delete_file(pid_file)
|
@@ -26,6 +28,7 @@ class TestBatchbase < Test::Unit::TestCase
|
|
26
28
|
delete_file(Batch::TEST_FILE) # HACKME したとまとめる、、、
|
27
29
|
delete_file(FILE_PG_TEST)
|
28
30
|
delete_file(LOG_FILE)
|
31
|
+
delete_file(RECEIVE_SIGNAL_FILE)
|
29
32
|
end
|
30
33
|
|
31
34
|
def new_batch_instance
|
@@ -254,6 +257,23 @@ class TestBatchbase < Test::Unit::TestCase
|
|
254
257
|
assert_equal false,File.exists?(PID_FILE_FORCE)
|
255
258
|
end
|
256
259
|
|
260
|
+
def test_signal_other_obj
|
261
|
+
assert_equal false,File.exists?(PID_FILE_FORCE)
|
262
|
+
assert_equal false,File.exists?(RECEIVE_SIGNAL_FILE)
|
263
|
+
pid = fork do
|
264
|
+
b = BatchSignalOtherClass.new
|
265
|
+
b.skip_logging
|
266
|
+
b.proceed(:pid_file=>PID_FILE_FORCE,:not_set_observer=>true)
|
267
|
+
end
|
268
|
+
sleep 1
|
269
|
+
assert_equal false,File.exists?(RECEIVE_SIGNAL_FILE)
|
270
|
+
pid_by_file = File.read(PID_FILE_FORCE).chomp.to_i
|
271
|
+
assert_equal pid,pid_by_file
|
272
|
+
`kill #{pid}`
|
273
|
+
sleep 1
|
274
|
+
assert_equal true,File.exists?(RECEIVE_SIGNAL_FILE)
|
275
|
+
end
|
276
|
+
|
257
277
|
#
|
258
278
|
# オブザーバーを設定していない場合は
|
259
279
|
# デフォルトの挙動をするように変更して
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: batchbase
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-01-
|
12
|
+
date: 2013-01-20 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: sys-proctable
|
@@ -63,6 +63,7 @@ files:
|
|
63
63
|
- readme.md
|
64
64
|
- test/batch.rb
|
65
65
|
- test/batch_by_hand.rb
|
66
|
+
- test/batch_signal_other_class.rb
|
66
67
|
- test/batch_too_long.rb
|
67
68
|
- test/by_hand.rb
|
68
69
|
- test/check_logger.rb
|
@@ -96,9 +97,11 @@ summary: oreore batch base class
|
|
96
97
|
test_files:
|
97
98
|
- test/batch.rb
|
98
99
|
- test/batch_by_hand.rb
|
100
|
+
- test/batch_signal_other_class.rb
|
99
101
|
- test/batch_too_long.rb
|
100
102
|
- test/by_hand.rb
|
101
103
|
- test/check_logger.rb
|
102
104
|
- test/pg_for_test.rb
|
103
105
|
- test/test.rb
|
104
106
|
- test/test_helper.rb
|
107
|
+
has_rdoc:
|