noda 0.0.8 → 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/VERSION +1 -1
- data/bin/noda_job_worker +4 -2
- data/lib/noda/job_server.rb +10 -0
- data/lib/noda/job_worker.rb +7 -2
- data/test/test_job_server.rb +38 -16
- data/test/test_job_worker.rb +28 -7
- data/test/test_table_saver_woker.rb +5 -5
- metadata +4 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.9
|
data/bin/noda_job_worker
CHANGED
@@ -20,8 +20,10 @@ options = {
|
|
20
20
|
require "socket"
|
21
21
|
ip=TCPSocket.gethostbyname(Socket::gethostname).last
|
22
22
|
STDOUT.puts " connect to job_server at druby://#{ip}:10001"
|
23
|
+
STDOUT.puts " job_worekr working at druby://#{ip}:10101"
|
23
24
|
Daemons.run_proc("job_worker",options){
|
24
|
-
|
25
|
-
|
25
|
+
w=Noda::JobWorker.new("#{ip}", "10001")
|
26
|
+
t = DRb.start_service("druby://#{ip}:10101",w)
|
27
|
+
w.start_service
|
26
28
|
}
|
27
29
|
|
data/lib/noda/job_server.rb
CHANGED
@@ -10,6 +10,7 @@ class JobServer
|
|
10
10
|
@server = DRb.start_service("druby://#{addr}:#{port}",self)
|
11
11
|
@thread = @server.thread
|
12
12
|
@logger = Logger.new(log_file)
|
13
|
+
@task_class_source_list = {}
|
13
14
|
end
|
14
15
|
def stop
|
15
16
|
@server.stop_service
|
@@ -33,6 +34,15 @@ class JobServer
|
|
33
34
|
def logger
|
34
35
|
@logger
|
35
36
|
end
|
37
|
+
def add_task_class(class_name, source_code)
|
38
|
+
@task_class_source_list[class_name] = source_code
|
39
|
+
end
|
40
|
+
def task_class(class_name)
|
41
|
+
@task_class_source_list[class_name]
|
42
|
+
end
|
43
|
+
def task_class_source_list
|
44
|
+
@task_class_source_list
|
45
|
+
end
|
36
46
|
end
|
37
47
|
|
38
48
|
|
data/lib/noda/job_worker.rb
CHANGED
@@ -11,6 +11,7 @@ class JobWorker
|
|
11
11
|
require "socket"
|
12
12
|
@local_addr = IPSocket::getaddress(Socket::gethostname)
|
13
13
|
self.connect
|
14
|
+
self
|
14
15
|
end
|
15
16
|
def connect_job_server
|
16
17
|
error_conter = 0
|
@@ -28,11 +29,15 @@ class JobWorker
|
|
28
29
|
def handle_task()
|
29
30
|
# @logger.info("self.class@#{@local_addr}#{self.object_id}"){"i try to pop a task."}
|
30
31
|
task = @job.input.pop
|
31
|
-
|
32
|
-
# @logger.info("self.class@#{@local_addr}#{self.object_id}"){"i start handling a task-#{task.name}"}
|
32
|
+
self.load_class if task.class == DRb::DRbUnknown
|
33
33
|
result = task.do_task(@job.hash_table)
|
34
34
|
@job.output.push result
|
35
35
|
end
|
36
|
+
def load_class
|
37
|
+
@job.task_class_source_list.each{|k,v|
|
38
|
+
eval(v)
|
39
|
+
}
|
40
|
+
end
|
36
41
|
def init_thread
|
37
42
|
@table = @job.hash_table
|
38
43
|
@thread= Thread.new{
|
data/test/test_job_server.rb
CHANGED
@@ -12,17 +12,17 @@ class TestJobServer < Test::Unit::TestCase
|
|
12
12
|
def test_job_server_input_queue
|
13
13
|
#druby�o�R�Ő������u���b�N����邩�ǂ���
|
14
14
|
test_str = "hello world"
|
15
|
-
s=JobServer.new
|
16
|
-
m = m = DRbObject.new_with_uri('druby://localhost:
|
15
|
+
s=JobServer.new("localhost", "10002")
|
16
|
+
m = m = DRbObject.new_with_uri('druby://localhost:10002')
|
17
17
|
t1 = Thread.new{
|
18
|
-
m1 = DRbObject.new_with_uri('druby://localhost:
|
18
|
+
m1 = DRbObject.new_with_uri('druby://localhost:10002')
|
19
19
|
q1 = m1.input
|
20
20
|
q1.pop
|
21
21
|
|
22
22
|
}
|
23
23
|
#�u���b�N����Ă��邩
|
24
24
|
assert t1.status == "sleep"
|
25
|
-
m2 = DRbObject.new_with_uri('druby://localhost:
|
25
|
+
m2 = DRbObject.new_with_uri('druby://localhost:10002')
|
26
26
|
q2 = m2.input
|
27
27
|
q2.push test_str
|
28
28
|
#�u���b�N��������ꂩ�ǂ���
|
@@ -33,17 +33,17 @@ class TestJobServer < Test::Unit::TestCase
|
|
33
33
|
def test_job_server_output_queue
|
34
34
|
#druby�o�R�Ő������u���b�N����邩�ǂ���
|
35
35
|
test_str = "hello world"
|
36
|
-
s=JobServer.new
|
37
|
-
m = m = DRbObject.new_with_uri('druby://localhost:
|
36
|
+
s=JobServer.new("localhost", "10003")
|
37
|
+
m = m = DRbObject.new_with_uri('druby://localhost:10003')
|
38
38
|
t1 = Thread.new{
|
39
|
-
m1 = DRbObject.new_with_uri('druby://localhost:
|
39
|
+
m1 = DRbObject.new_with_uri('druby://localhost:10003')
|
40
40
|
q1 = m1.output
|
41
41
|
q1.pop
|
42
42
|
|
43
43
|
}
|
44
44
|
#�u���b�N����Ă��邩
|
45
45
|
assert t1.status == "sleep"
|
46
|
-
m2 = DRbObject.new_with_uri('druby://localhost:
|
46
|
+
m2 = DRbObject.new_with_uri('druby://localhost:10003')
|
47
47
|
q2 = m2.output
|
48
48
|
q2.push test_str
|
49
49
|
#�u���b�N��������ꂩ�ǂ���
|
@@ -52,34 +52,56 @@ class TestJobServer < Test::Unit::TestCase
|
|
52
52
|
s.stop
|
53
53
|
end
|
54
54
|
def test_job_server_input_queue_data
|
55
|
-
s=JobServer.new
|
56
|
-
m = m = DRbObject.new_with_uri('druby://localhost:
|
55
|
+
s=JobServer.new("localhost", "10004")
|
56
|
+
m = m = DRbObject.new_with_uri('druby://localhost:10004')
|
57
57
|
t1 = Thread.new{
|
58
|
-
m1 = DRbObject.new_with_uri('druby://localhost:
|
58
|
+
m1 = DRbObject.new_with_uri('druby://localhost:10004')
|
59
59
|
q1 = m1.input
|
60
60
|
q1.push "hello world"
|
61
61
|
|
62
62
|
}
|
63
|
-
m2 = DRbObject.new_with_uri('druby://localhost:
|
63
|
+
m2 = DRbObject.new_with_uri('druby://localhost:10004')
|
64
64
|
q2 = m2.input
|
65
65
|
ret = q2.pop
|
66
66
|
assert ret == "hello world"
|
67
67
|
s.stop
|
68
68
|
end
|
69
69
|
def test_job_server_output_queue_data
|
70
|
-
s=JobServer.new
|
71
|
-
m = m = DRbObject.new_with_uri('druby://localhost:
|
70
|
+
s=JobServer.new("localhost", "10005")
|
71
|
+
m = m = DRbObject.new_with_uri('druby://localhost:10005')
|
72
72
|
t1 = Thread.new{
|
73
|
-
m1 = DRbObject.new_with_uri('druby://localhost:
|
73
|
+
m1 = DRbObject.new_with_uri('druby://localhost:10005')
|
74
74
|
q1 = m1.output
|
75
75
|
q1.push "hello world"
|
76
76
|
|
77
77
|
}
|
78
|
-
m2 = DRbObject.new_with_uri('druby://localhost:
|
78
|
+
m2 = DRbObject.new_with_uri('druby://localhost:10005')
|
79
79
|
q2 = m2.output
|
80
80
|
ret = q2.pop
|
81
81
|
assert ret == "hello world"
|
82
82
|
s.stop
|
83
83
|
end
|
84
|
+
def test_job_server_add_class_source_code
|
85
|
+
s=JobServer.new("localhost", "10006")
|
86
|
+
str1 = "class MyTestUnitTask\n end"
|
87
|
+
s.add_task_class("MyTestUnitTask", str1)
|
88
|
+
str2 = s.task_class("MyTestUnitTask")
|
89
|
+
assert str1 == str1
|
90
|
+
e = nil
|
91
|
+
begin
|
92
|
+
t = MyTestUnitTask.class
|
93
|
+
rescue NameError => e
|
94
|
+
ensure
|
95
|
+
assert e !=nil
|
96
|
+
end
|
97
|
+
eval(str2)
|
98
|
+
assert MyTestUnitTask.class == Class
|
99
|
+
|
100
|
+
m1 = DRbObject.new_with_uri('druby://localhost:10006')
|
101
|
+
str3 = m1.task_class("MyTestUnitTask")
|
102
|
+
assert str1 == str3
|
103
|
+
s.stop
|
104
|
+
end
|
84
105
|
end
|
85
106
|
|
107
|
+
|
data/test/test_job_worker.rb
CHANGED
@@ -3,7 +3,8 @@ class TestJobWoker < Test::Unit::TestCase
|
|
3
3
|
|
4
4
|
|
5
5
|
def test_init_job_woker
|
6
|
-
|
6
|
+
s=JobServer.new("localhost", "10001")
|
7
|
+
worker = JobWorker.new("localhost", "10001")
|
7
8
|
assert worker
|
8
9
|
end
|
9
10
|
#test task
|
@@ -13,8 +14,8 @@ class TestJobWoker < Test::Unit::TestCase
|
|
13
14
|
end
|
14
15
|
end
|
15
16
|
def test_start_stop
|
16
|
-
s
|
17
|
-
w = JobWorker.new
|
17
|
+
s=JobServer.new("localhost", "10002")
|
18
|
+
w = JobWorker.new("localhost", "10002")
|
18
19
|
t = Thread.new{
|
19
20
|
w.start
|
20
21
|
}
|
@@ -26,8 +27,8 @@ class TestJobWoker < Test::Unit::TestCase
|
|
26
27
|
assert w.status == false #�X���b�h�I���ł����H
|
27
28
|
end
|
28
29
|
def test_do_task
|
29
|
-
s=JobServer.new
|
30
|
-
worker = JobWorker.new
|
30
|
+
s=JobServer.new("localhost", "10003")
|
31
|
+
worker = JobWorker.new("localhost", "10003")
|
31
32
|
s.input.push MyTask.new
|
32
33
|
worker.handle_task
|
33
34
|
ret = s.output.pop
|
@@ -42,8 +43,8 @@ class TestJobWoker < Test::Unit::TestCase
|
|
42
43
|
end
|
43
44
|
def test_task_write_hash_table
|
44
45
|
#�W���u�T�[�o�[�̋��L�̈�ɏ������߂邩�ǂ���
|
45
|
-
s=JobServer.new
|
46
|
-
worker = JobWorker.new
|
46
|
+
s=JobServer.new("localhost", "10004")
|
47
|
+
worker = JobWorker.new("localhost", "10004")
|
47
48
|
s.input.push MyTask2.new
|
48
49
|
worker.handle_task
|
49
50
|
ret = s.output.pop
|
@@ -52,4 +53,24 @@ class TestJobWoker < Test::Unit::TestCase
|
|
52
53
|
assert v == "foooo"
|
53
54
|
s.stop
|
54
55
|
end
|
56
|
+
def test_task_class_load
|
57
|
+
s=JobServer.new("localhost", "10005")
|
58
|
+
worker = JobWorker.new("localhost", "10005")
|
59
|
+
str = "class MyTaskTime\n
|
60
|
+
attr_accessor :name
|
61
|
+
def initialize(name)
|
62
|
+
@name = name
|
63
|
+
end
|
64
|
+
def do_task(hash)
|
65
|
+
return self.name+1.to_s
|
66
|
+
end
|
67
|
+
end
|
68
|
+
"
|
69
|
+
s.add_task_class("MyTaskTime",str)
|
70
|
+
eval(str)
|
71
|
+
s.input.push MyTaskTime.new("test_task")
|
72
|
+
worker.handle_task
|
73
|
+
ret = s.output.pop
|
74
|
+
assert ret == "test_task1"
|
75
|
+
end
|
55
76
|
end
|
@@ -3,14 +3,14 @@ Thread.abort_on_exception=true
|
|
3
3
|
|
4
4
|
class TestTableSaverWorker < Test::Unit::TestCase
|
5
5
|
def test_table_saver_initialize
|
6
|
-
s = JobServer.new("localhost","
|
6
|
+
s = JobServer.new("localhost","10011")
|
7
7
|
saver = TableAutoSaver.new
|
8
8
|
saver.interval = 12
|
9
9
|
assert saver.interval == 12
|
10
10
|
end
|
11
11
|
def test_table_saver_save_dir
|
12
|
-
s = JobServer.new("localhost","
|
13
|
-
saver = TableAutoSaver.new("localhost","
|
12
|
+
s = JobServer.new("localhost","10012")
|
13
|
+
saver = TableAutoSaver.new("localhost","10012")
|
14
14
|
begin
|
15
15
|
saver.save_dir = Dir.tmpdir + "a"
|
16
16
|
rescue => e
|
@@ -23,8 +23,8 @@ class TestTableSaverWorker < Test::Unit::TestCase
|
|
23
23
|
assert FileTest.exists? d == false
|
24
24
|
end
|
25
25
|
def test_table_saver_save_dir
|
26
|
-
s = JobServer.new("localhost","
|
27
|
-
saver = TableAutoSaver.new("localhost","
|
26
|
+
s = JobServer.new("localhost","10013")
|
27
|
+
saver = TableAutoSaver.new("localhost","10013")
|
28
28
|
t1 = saver.init_thread
|
29
29
|
t2 = Thread.new{
|
30
30
|
s.hash_table.put("aaaa",1234)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 13
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 0
|
9
|
-
-
|
10
|
-
version: 0.0.
|
9
|
+
- 9
|
10
|
+
version: 0.0.9
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- takuya
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-
|
18
|
+
date: 2011-06-03 00:00:00 +09:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|