comana 0.0.2 → 0.0.3
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/VERSION +1 -1
- data/comana.gemspec +13 -3
- data/lib/comana.rb +5 -27
- data/spec/comana_spec.rb +50 -104
- data/spec/locked/lock +0 -0
- data/spec/locked_outputted/input_a +0 -0
- data/spec/locked_outputted/input_b +0 -0
- data/spec/locked_outputted/lock +0 -0
- data/spec/locked_outputted/output +0 -0
- data/spec/not_calculated/input_a +0 -0
- data/spec/not_calculated/input_b +0 -0
- data/spec/outputted/input_a +0 -0
- data/spec/outputted/input_b +0 -0
- data/spec/outputted/output +0 -0
- metadata +24 -14
- /data/spec/{dummy → locked}/input_a +0 -0
- /data/spec/{dummy → locked}/input_b +0 -0
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/comana.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "comana"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["ippei94da"]
|
@@ -27,8 +27,18 @@ Gem::Specification.new do |s|
|
|
27
27
|
"comana.gemspec",
|
28
28
|
"lib/comana.rb",
|
29
29
|
"spec/comana_spec.rb",
|
30
|
-
"spec/
|
31
|
-
"spec/
|
30
|
+
"spec/locked/input_a",
|
31
|
+
"spec/locked/input_b",
|
32
|
+
"spec/locked/lock",
|
33
|
+
"spec/locked_outputted/input_a",
|
34
|
+
"spec/locked_outputted/input_b",
|
35
|
+
"spec/locked_outputted/lock",
|
36
|
+
"spec/locked_outputted/output",
|
37
|
+
"spec/not_calculated/input_a",
|
38
|
+
"spec/not_calculated/input_b",
|
39
|
+
"spec/outputted/input_a",
|
40
|
+
"spec/outputted/input_b",
|
41
|
+
"spec/outputted/output",
|
32
42
|
"spec/spec_helper.rb"
|
33
43
|
]
|
34
44
|
s.homepage = "http://github.com/ippei94da/comana"
|
data/lib/comana.rb
CHANGED
@@ -23,11 +23,9 @@ class Comana
|
|
23
23
|
# :yet not started
|
24
24
|
# :started started, but not ended, including short time from last output
|
25
25
|
# :terminated started, but long time no output
|
26
|
-
# :next started, normal ended and need next calculation
|
27
26
|
# :finished started, normal ended and not need next calculation
|
28
27
|
def state
|
29
28
|
return :finished if finished?
|
30
|
-
return :next if normal_ended?
|
31
29
|
return :yet unless started?
|
32
30
|
return :terminated if (Time.now - latest_modified_time > @alive_time)
|
33
31
|
return :started
|
@@ -38,25 +36,10 @@ class Comana
|
|
38
36
|
# because the calculation has been done by other process already.
|
39
37
|
def calculate
|
40
38
|
raise AlreadyStartedError if started?
|
41
|
-
File.open(@
|
39
|
+
File.open(@lockfile, "w")
|
42
40
|
send_command
|
43
41
|
end
|
44
42
|
|
45
|
-
# Generate next calculation and return the computation object.
|
46
|
-
def prepare_next
|
47
|
-
raise NotImplementedError, "#{self.class}::prepare_next need to be redefined"
|
48
|
-
end
|
49
|
-
|
50
|
-
# Return initial state.
|
51
|
-
def initial_state
|
52
|
-
raise NotImplementedError, "#{self.class}::initial_state need to be redefined"
|
53
|
-
end
|
54
|
-
|
55
|
-
# Return latest state.
|
56
|
-
def latest_state
|
57
|
-
raise NotImplementedError, "#{self.class}::latest_state need to be redefined"
|
58
|
-
end
|
59
|
-
|
60
43
|
private
|
61
44
|
|
62
45
|
def send_command
|
@@ -67,13 +50,14 @@ class Comana
|
|
67
50
|
raise NotImplementedError, "#{self.class}::set_parameters need to be redefined"
|
68
51
|
|
69
52
|
# e.g.,
|
70
|
-
#@
|
53
|
+
#@lockfile = "comana.lock"
|
71
54
|
#@alive_time = 3600
|
72
55
|
#@outfiles = ["output_a", "ouput_b"] # Files only to output should be indicated.
|
73
56
|
end
|
74
57
|
|
75
58
|
# Return latest modified time of files in calc dir recursively.
|
76
|
-
#require "find"
|
59
|
+
# require "find"
|
60
|
+
# Not only @outfiles, to catch an irregular state at the beginning before output.
|
77
61
|
def latest_modified_time
|
78
62
|
tmp = Dir.glob("#{@dir}/**/*").max_by do |file|
|
79
63
|
File.mtime(file)
|
@@ -82,7 +66,7 @@ class Comana
|
|
82
66
|
end
|
83
67
|
|
84
68
|
def started?
|
85
|
-
return true if File.exist?( "#{@dir}/#{@
|
69
|
+
return true if File.exist?( "#{@dir}/#{@lockfile}" )
|
86
70
|
@outfiles.each do |file|
|
87
71
|
return true if File.exist?( "#{@dir}/#{file}" )
|
88
72
|
end
|
@@ -91,12 +75,6 @@ class Comana
|
|
91
75
|
|
92
76
|
# Return true if the condition is satisfied.
|
93
77
|
# E.g., when calculation output contains orthodox ending sequences.
|
94
|
-
def normal_ended?
|
95
|
-
raise NotImplementedError, "#{self.class}::normal_ended? need to be redefined"
|
96
|
-
end
|
97
|
-
|
98
|
-
# Return true if the condition is satisfied.
|
99
|
-
# E.g., calculation achieve convergence.
|
100
78
|
def finished?
|
101
79
|
raise NotImplementedError, "#{self.class}::finished? need to be redefined"
|
102
80
|
end
|
data/spec/comana_spec.rb
CHANGED
@@ -2,40 +2,31 @@ require "fileutils"
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
3
3
|
|
4
4
|
NOW = Time.now
|
5
|
-
CALC_DIR = "spec/dummy"
|
6
|
-
LOCKFILE = "#{CALC_DIR}/
|
7
|
-
OUTFILES = ["#{CALC_DIR}/output_a", "#{CALC_DIR}/output_b"]
|
5
|
+
#CALC_DIR = "spec/dummy"
|
6
|
+
#LOCKFILE = "#{CALC_DIR}/lock"
|
7
|
+
#OUTFILES = ["#{CALC_DIR}/output_a", "#{CALC_DIR}/output_b"]
|
8
8
|
|
9
9
|
class Comana
|
10
10
|
public :latest_modified_time, :started?
|
11
11
|
end
|
12
12
|
|
13
|
-
|
14
|
-
def normal_ended? ; true ; end
|
15
|
-
def finished? ; true ; end
|
16
|
-
def set_parameters
|
17
|
-
@logfile = "log"
|
18
|
-
@alive_time = 500
|
19
|
-
@outfiles = []
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe Comana, "with not calculated" do
|
13
|
+
describe Comana, "not calculated" do
|
24
14
|
class CalcYet < Comana
|
25
|
-
def normal_ended? ; false ; end
|
26
15
|
def finished? ; false ; end
|
27
16
|
def set_parameters
|
28
|
-
@
|
17
|
+
@lockfile = "lock"
|
29
18
|
@alive_time = 3600
|
30
|
-
@outfiles =
|
19
|
+
@outfiles = ["output"]
|
31
20
|
end
|
32
21
|
end
|
33
22
|
before do
|
34
|
-
|
23
|
+
calc_dir = "spec/not_calculated"
|
24
|
+
@calc = CalcYet.new(calc_dir)
|
35
25
|
|
36
|
-
File.utime(NOW - 1000 ,NOW - 1000, "#{
|
37
|
-
File.utime(NOW - 2000 ,NOW - 2000, "#{
|
38
|
-
|
26
|
+
File.utime(NOW - 1000 ,NOW - 1000, "#{calc_dir}/input_a")
|
27
|
+
File.utime(NOW - 2000 ,NOW - 2000, "#{calc_dir}/input_b")
|
28
|
+
@lockfile = "#{calc_dir}/lockfile"
|
29
|
+
FileUtils.rm(@lockfile) if File.exist?(@lockfile)
|
39
30
|
end
|
40
31
|
|
41
32
|
it "should return the state" do
|
@@ -46,155 +37,110 @@ describe Comana, "with not calculated" do
|
|
46
37
|
@calc.latest_modified_time.should == (NOW - 1000)
|
47
38
|
end
|
48
39
|
|
49
|
-
it "should return false without
|
40
|
+
it "should return false without lock." do
|
50
41
|
@calc.started?.should_not == nil
|
51
42
|
@calc.started?.should be_false
|
52
43
|
end
|
53
44
|
|
54
|
-
it "should return true with
|
55
|
-
|
56
|
-
@calc.started?.should be_true
|
45
|
+
it "should return true with lock." do
|
46
|
+
@calc.started?.should be_false
|
57
47
|
end
|
58
48
|
|
59
|
-
after do
|
60
|
-
|
61
|
-
end
|
49
|
+
#after do
|
50
|
+
# FileUtils.rm(@lockfile) if File.exist?(@lockfile)
|
51
|
+
#end
|
62
52
|
end
|
63
53
|
|
64
|
-
describe Comana, "with
|
54
|
+
describe Comana, "with lock" do
|
65
55
|
class CalcStarted < Comana
|
66
|
-
def normal_ended? ; false ; end
|
67
56
|
def finished? ; false ; end
|
68
57
|
def set_parameters
|
69
|
-
@
|
58
|
+
@lockfile = "lock"
|
70
59
|
@alive_time = 5000
|
71
|
-
@outfiles =
|
60
|
+
@outfiles = ["output"]
|
72
61
|
end
|
73
62
|
end
|
74
63
|
|
75
64
|
before do
|
76
|
-
|
77
|
-
|
78
|
-
File.utime(NOW -
|
79
|
-
File.
|
65
|
+
calc_dir = "spec/locked"
|
66
|
+
@calc = CalcStarted .new(calc_dir)
|
67
|
+
File.utime(NOW - 1000 ,NOW - 1000, "#{calc_dir}/input_a")
|
68
|
+
File.utime(NOW - 2000 ,NOW - 2000, "#{calc_dir}/input_b")
|
80
69
|
end
|
81
70
|
|
82
71
|
it "should return :started" do
|
83
72
|
@calc.state.should == :started
|
84
73
|
end
|
85
|
-
|
86
|
-
after do
|
87
|
-
FileUtils.rm(LOCKFILE) if File.exist?(LOCKFILE)
|
88
|
-
end
|
89
74
|
end
|
90
75
|
|
91
76
|
describe Comana, "with output, without lock" do
|
92
77
|
class CalcStarted < Comana
|
93
|
-
def normal_ended? ; false ; end
|
94
78
|
def finished? ; false ; end
|
95
79
|
def set_parameters
|
96
|
-
@
|
80
|
+
@lockfile = "lock"
|
97
81
|
@alive_time = 5000
|
98
|
-
@outfiles =
|
99
|
-
@outfiles = ["output_a", "output_b"]
|
82
|
+
@outfiles = ["output"]
|
100
83
|
end
|
101
84
|
end
|
102
85
|
|
103
86
|
before do
|
104
|
-
|
105
|
-
|
106
|
-
File.utime(NOW -
|
107
|
-
File.
|
87
|
+
calc_dir = "spec/outputted"
|
88
|
+
@calc = CalcStarted .new(calc_dir)
|
89
|
+
File.utime(NOW - 1000 ,NOW - 1000, "#{calc_dir}/input_a")
|
90
|
+
File.utime(NOW - 2000 ,NOW - 2000, "#{calc_dir}/input_b")
|
91
|
+
File.utime(NOW - 2000 ,NOW - 2000, "#{calc_dir}/output")
|
92
|
+
#File.open(OUTFILES[0], "w")
|
108
93
|
end
|
109
94
|
|
110
95
|
it "should return :started" do
|
111
96
|
@calc.state.should == :started
|
112
97
|
end
|
113
98
|
|
114
|
-
after do
|
115
|
-
FileUtils.rm(OUTFILES[0]) if File.exist?(OUTFILES[0])
|
116
|
-
end
|
117
99
|
end
|
118
100
|
|
119
|
-
describe Comana, "
|
101
|
+
describe Comana, "terminated" do
|
120
102
|
class CalcTerminated < Comana
|
121
|
-
def normal_ended? ; false ; end
|
122
103
|
def finished? ; false ; end
|
123
104
|
def set_parameters
|
124
|
-
@
|
105
|
+
@lockfile = "lock"
|
125
106
|
@alive_time = 500
|
126
|
-
@outfiles =
|
107
|
+
@outfiles = ["output"]
|
127
108
|
end
|
128
109
|
end
|
129
110
|
|
130
111
|
before do
|
131
|
-
|
112
|
+
calc_dir = "spec/locked_outputted"
|
113
|
+
@calc_terminated = CalcTerminated.new(calc_dir)
|
132
114
|
|
133
|
-
File.utime(NOW - 1000 ,NOW - 1000, "#{
|
134
|
-
File.utime(NOW - 2000 ,NOW - 2000, "#{
|
135
|
-
File.
|
115
|
+
File.utime(NOW - 1000 ,NOW - 1000, "#{calc_dir}/input_a")
|
116
|
+
File.utime(NOW - 2000 ,NOW - 2000, "#{calc_dir}/input_b")
|
117
|
+
File.utime(NOW - 9000 ,NOW - 9000, "#{calc_dir}/output")
|
136
118
|
end
|
137
119
|
|
138
120
|
it "should return the state" do
|
139
|
-
File.open(LOCKFILE, "w")
|
140
|
-
File.utime(NOW - 1000 ,NOW - 1000, LOCKFILE)
|
141
121
|
@calc_terminated .state.should == :terminated
|
142
122
|
end
|
143
|
-
|
144
|
-
after do
|
145
|
-
FileUtils.rm(LOCKFILE) if File.exist?(LOCKFILE)
|
146
|
-
end
|
147
123
|
end
|
148
124
|
|
149
|
-
describe Comana, "
|
150
|
-
class
|
151
|
-
def
|
152
|
-
def finished? ; false ; end
|
125
|
+
describe Comana, "finished" do
|
126
|
+
class CalcFinished < Comana
|
127
|
+
def finished? ; true ; end
|
153
128
|
def set_parameters
|
154
|
-
@
|
129
|
+
@lockfile = "lock"
|
155
130
|
@alive_time = 500
|
156
|
-
@outfiles =
|
131
|
+
@outfiles = ["output"]
|
157
132
|
end
|
158
133
|
end
|
159
134
|
|
160
135
|
before do
|
161
|
-
|
136
|
+
calc_dir = "spec/locked_outputted"
|
137
|
+
@calc_finished = CalcFinished .new(calc_dir)
|
162
138
|
|
163
|
-
File.utime(NOW - 1000 ,NOW - 1000, "#{
|
164
|
-
File.utime(NOW - 2000 ,NOW - 2000, "#{
|
165
|
-
File.open(LOCKFILE, "w")
|
139
|
+
File.utime(NOW - 1000 ,NOW - 1000, "#{calc_dir}/input_a")
|
140
|
+
File.utime(NOW - 2000 ,NOW - 2000, "#{calc_dir}/input_b")
|
166
141
|
end
|
167
142
|
|
168
143
|
it "should return the state" do
|
169
|
-
|
170
|
-
File.open(LOCKFILE, "w")
|
171
|
-
File.utime(NOW - 1000 ,NOW - 1000, LOCKFILE)
|
172
|
-
@calc_next .state.should == :next
|
173
|
-
end
|
174
|
-
|
175
|
-
after do
|
176
|
-
FileUtils.rm(LOCKFILE) if File.exist?(LOCKFILE)
|
177
|
-
end
|
178
|
-
end
|
179
|
-
|
180
|
-
describe Comana, "with finished" do
|
181
|
-
before do
|
182
|
-
@calc_finished = CalcFinished .new(CALC_DIR)
|
183
|
-
|
184
|
-
File.utime(NOW - 1000 ,NOW - 1000, "#{CALC_DIR}/input_a")
|
185
|
-
File.utime(NOW - 2000 ,NOW - 2000, "#{CALC_DIR}/input_b")
|
186
|
-
#FileUtils.rm(LOCKFILE) if File.exist?(LOCKFILE)
|
187
|
-
File.open(LOCKFILE, "w")
|
188
|
-
end
|
189
|
-
|
190
|
-
it "should return the state" do
|
191
|
-
|
192
|
-
File.open(LOCKFILE, "w")
|
193
|
-
File.utime(NOW - 1000 ,NOW - 1000, LOCKFILE)
|
194
144
|
@calc_finished .state.should == :finished
|
195
145
|
end
|
196
|
-
|
197
|
-
after do
|
198
|
-
FileUtils.rm(LOCKFILE) if File.exist?(LOCKFILE)
|
199
|
-
end
|
200
146
|
end
|
data/spec/locked/lock
ADDED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: comana
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-04-23 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &85029320 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: 2.9.0
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *85029320
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rdoc
|
27
|
-
requirement: &
|
27
|
+
requirement: &85026760 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ~>
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '3.12'
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *85026760
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: bundler
|
38
|
-
requirement: &
|
38
|
+
requirement: &85026410 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -43,10 +43,10 @@ dependencies:
|
|
43
43
|
version: 1.1.3
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *85026410
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: jeweler
|
49
|
-
requirement: &
|
49
|
+
requirement: &85025660 !ruby/object:Gem::Requirement
|
50
50
|
none: false
|
51
51
|
requirements:
|
52
52
|
- - ~>
|
@@ -54,10 +54,10 @@ dependencies:
|
|
54
54
|
version: 1.8.3
|
55
55
|
type: :development
|
56
56
|
prerelease: false
|
57
|
-
version_requirements: *
|
57
|
+
version_requirements: *85025660
|
58
58
|
- !ruby/object:Gem::Dependency
|
59
59
|
name: simplecov
|
60
|
-
requirement: &
|
60
|
+
requirement: &85040750 !ruby/object:Gem::Requirement
|
61
61
|
none: false
|
62
62
|
requirements:
|
63
63
|
- - ! '>='
|
@@ -65,7 +65,7 @@ dependencies:
|
|
65
65
|
version: '0'
|
66
66
|
type: :development
|
67
67
|
prerelease: false
|
68
|
-
version_requirements: *
|
68
|
+
version_requirements: *85040750
|
69
69
|
description: ! "An aim of this gem is to provide a framework of\n managing scientific
|
70
70
|
computing.\n Researchers on computing have to check calculation and\n generate
|
71
71
|
new calculation and execute, repeatedly.\n The abstract class that this gem provide
|
@@ -87,8 +87,18 @@ files:
|
|
87
87
|
- comana.gemspec
|
88
88
|
- lib/comana.rb
|
89
89
|
- spec/comana_spec.rb
|
90
|
-
- spec/
|
91
|
-
- spec/
|
90
|
+
- spec/locked/input_a
|
91
|
+
- spec/locked/input_b
|
92
|
+
- spec/locked/lock
|
93
|
+
- spec/locked_outputted/input_a
|
94
|
+
- spec/locked_outputted/input_b
|
95
|
+
- spec/locked_outputted/lock
|
96
|
+
- spec/locked_outputted/output
|
97
|
+
- spec/not_calculated/input_a
|
98
|
+
- spec/not_calculated/input_b
|
99
|
+
- spec/outputted/input_a
|
100
|
+
- spec/outputted/input_b
|
101
|
+
- spec/outputted/output
|
92
102
|
- spec/spec_helper.rb
|
93
103
|
homepage: http://github.com/ippei94da/comana
|
94
104
|
licenses:
|
@@ -105,7 +115,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
105
115
|
version: '0'
|
106
116
|
segments:
|
107
117
|
- 0
|
108
|
-
hash:
|
118
|
+
hash: 813074803
|
109
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
110
120
|
none: false
|
111
121
|
requirements:
|
File without changes
|
File without changes
|