rub2 0.1.0 → 0.2.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.
- checksums.yaml +5 -5
- data/{README.txt → README.md} +26 -17
- data/lib/rub2.rb +34 -13
- data/lib/rub2/version.rb +1 -1
- metadata +4 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f3c4e11450cfc56d7a6171bd2a59322cc927bb03d4680519cbfce7fcf61a7bf8
|
4
|
+
data.tar.gz: 676b2f0326d75c31e760547e81df36f154036d42133c78baadecf0908ee78281
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f9be823b44ad553bf7f402d2639fcbe5a8bc7d8e913e02183fad46455996e341cbac23be3ed9567335314796e2fb807e100265893e411e8a8539d11674b2e417
|
7
|
+
data.tar.gz: 487085194ebfcc7b6f045f5de1e2bb393cf0c6dee34983423208654ad9805e4237a250342ab5bf798be60a8e11934d54e125308e07d9a1c84ea1d218e33b33cc
|
data/{README.txt → README.md}
RENAMED
@@ -1,24 +1,32 @@
|
|
1
|
-
|
1
|
+
# rub2
|
2
2
|
|
3
|
-
wrapper for qsub
|
3
|
+
wrapper for torque qsub
|
4
4
|
|
5
|
-
|
5
|
+
## install
|
6
6
|
|
7
|
+
```shell
|
8
|
+
gem install rub2
|
9
|
+
```
|
10
|
+
|
11
|
+
## sample
|
12
|
+
|
13
|
+
```ruby
|
7
14
|
require 'rub2'
|
8
15
|
|
9
16
|
submit "SimpleJob" do
|
10
|
-
execute_with Dir.glob("/etc/*.conf") do |
|
11
|
-
"wc -l #{
|
17
|
+
execute_with Dir.glob("/etc/*.conf") do |file|
|
18
|
+
"wc -l #{file}"
|
12
19
|
end
|
13
20
|
end
|
14
21
|
# exit if job failed
|
15
22
|
|
16
23
|
|
17
|
-
submit "WithOptions" do
|
18
|
-
log
|
24
|
+
submit "WithOptions" do |jobname|
|
25
|
+
log "log/#{jobname}.log" # log file path
|
19
26
|
resource 'nodes' => '1:ppn=4', 'mem' => '15mb' # qsub -l option
|
20
27
|
array_request 2..4 # or array_request [1, 3] # qsub -t option
|
21
28
|
inherit_environment # qsub -V option
|
29
|
+
queue 'batch' # qsub -q option
|
22
30
|
continue_on_error # don't exit on job failed
|
23
31
|
dry_run # output script and exit. no execute
|
24
32
|
|
@@ -40,45 +48,46 @@ submit "WithOptions" do
|
|
40
48
|
end
|
41
49
|
end
|
42
50
|
end
|
51
|
+
```
|
43
52
|
|
44
|
-
|
53
|
+
## 使い方
|
45
54
|
|
46
55
|
submit "JobName"で指定された名前でジョブを作成します。
|
47
56
|
submitブロック内でexecute_withの引数に配列を渡すと、配列の要素数分JobArrayを作成して、execute_withから返された文字列をbashの引数として実行します。
|
48
57
|
jobが全て成功するとsubmitブロックはtrueを返します。
|
49
58
|
|
50
|
-
|
59
|
+
## オプション
|
51
60
|
|
52
|
-
|
61
|
+
### log
|
53
62
|
|
54
63
|
ログファイル出力先。未指定の場合はカレントフォルダにログディレクトリを作成します。
|
55
64
|
|
56
|
-
|
65
|
+
### resource
|
57
66
|
|
58
67
|
qsub -lオプション。リソース名 => 値のハッシュを渡してください。
|
59
68
|
|
60
|
-
|
69
|
+
### array_request
|
61
70
|
|
62
71
|
実行するarray index。1-10の時は1..10のようにRangeを、1,2,4の時は[1,2,4]と配列を渡してください。
|
63
72
|
|
64
|
-
|
73
|
+
### inherit_environment
|
65
74
|
|
66
75
|
qsub -Vオプション。環境変数を引き継ぎます。
|
67
76
|
|
68
|
-
|
77
|
+
### dry_run
|
69
78
|
|
70
79
|
実行せずにsubmitするスクリプトを表示します。デバッグ向け。
|
71
80
|
|
72
|
-
|
81
|
+
### max_retry
|
73
82
|
|
74
83
|
max retry count
|
75
84
|
|
76
|
-
|
85
|
+
## ハンドラ
|
77
86
|
|
78
87
|
ジョブが成功した場合にはon_doneハンドラ、一つでも失敗した場合はon_failハンドラで指定されたブロックを実行します。
|
79
88
|
未指定の場合はデフォルトハンドラを実行し、失敗したジョブがあれば表示します。
|
80
89
|
|
81
90
|
|
82
|
-
その他
|
91
|
+
## その他
|
83
92
|
|
84
93
|
各jobの結果はRinda(dRuby)サーバーで受け取ります。 ネットワーク不調などにより結果が受け取れず終了しないときは適当にctrl-cで終らせてくさい。
|
data/lib/rub2.rb
CHANGED
@@ -14,9 +14,16 @@ module Rub2
|
|
14
14
|
module_function :putlog
|
15
15
|
|
16
16
|
class JobScript
|
17
|
-
attr_accessor :log,
|
18
|
-
|
19
|
-
|
17
|
+
attr_accessor :log,
|
18
|
+
:shell,
|
19
|
+
:resource,
|
20
|
+
:array_request,
|
21
|
+
:inherit_environment,
|
22
|
+
:commands,
|
23
|
+
:log_path,
|
24
|
+
:uri,
|
25
|
+
:queue
|
26
|
+
attr_reader :source, :name
|
20
27
|
|
21
28
|
def initialize(name)
|
22
29
|
@name = name
|
@@ -56,6 +63,7 @@ module Rub2
|
|
56
63
|
t = Time.now.strftime('%Y%m%d_%H%M%S')
|
57
64
|
Pathname.new(Dir.pwd).join("log_#{t}", "#{name}.log")
|
58
65
|
end
|
66
|
+
|
59
67
|
# return key=value[,key=value]
|
60
68
|
def make_pbs_resources_string
|
61
69
|
return '' if @resource.empty?
|
@@ -79,6 +87,9 @@ module Rub2
|
|
79
87
|
<%- if @inherit_environment -%>
|
80
88
|
#PBS -V
|
81
89
|
<%- end -%>
|
90
|
+
<%- if @queue -%>
|
91
|
+
#PBS -q <%= @queue %>
|
92
|
+
<%- end -%>
|
82
93
|
|
83
94
|
CMD=(
|
84
95
|
<% @commands.each do |i| -%>
|
@@ -90,11 +101,13 @@ cd $PBS_O_WORKDIR
|
|
90
101
|
echo "job start: $(date -Iminute)"
|
91
102
|
echo "$PBS_O_HOST -> $(hostname): $PBS_JOBNAME $PBS_JOBID (cwd: $PWD)"
|
92
103
|
echo "execute: ${CMD[$ID]}"
|
104
|
+
START_TIME=$(date +%s)
|
93
105
|
bash -c "set -e; set -o pipefail; ${CMD[$ID]}"
|
94
106
|
RET=$?
|
95
107
|
echo "job exit: $RET at: $(date -Iminute)"
|
108
|
+
EXIT_TIME=$(date +%s)
|
96
109
|
for i in {0..10}; do
|
97
|
-
ruby -r drb -e "DRbObject.new_with_uri('<%= @uri %>').write([<%= Process.pid %>, '$PBS_JOBID', $PBS_ARRAYID, '$HOSTNAME', $RET])"
|
110
|
+
ruby -r drb -e "DRbObject.new_with_uri('<%= @uri %>').write([<%= Process.pid %>, '$PBS_JOBID', $PBS_ARRAYID, '$HOSTNAME', $RET, $START_TIME, $EXIT_TIME])"
|
98
111
|
if [ $? -eq 0 ]; then
|
99
112
|
exit $RET
|
100
113
|
fi
|
@@ -106,7 +119,6 @@ EOS
|
|
106
119
|
|
107
120
|
end
|
108
121
|
|
109
|
-
|
110
122
|
class Job
|
111
123
|
attr_reader :parent_id, :array_id, :exit_code, :died_at
|
112
124
|
|
@@ -272,10 +284,12 @@ EOS
|
|
272
284
|
|
273
285
|
# block thread
|
274
286
|
def collect_job_result(job_store)
|
275
|
-
_pid, job_id, array_id, host, exit_code = @drb.take([@pid, nil, nil, nil, nil], @timeout)
|
287
|
+
_pid, job_id, array_id, host, exit_code, start_time, exit_time = @drb.take([@pid, nil, nil, nil, nil, nil, nil], @timeout)
|
276
288
|
job_store.update_exit_code([{:array_id => array_id, :exit_code => exit_code}])
|
277
289
|
@success_count += 1 if exit_code == 0
|
278
|
-
|
290
|
+
t = Time.at(exit_time) - Time.at(start_time)
|
291
|
+
min, sec = t.divmod(60)
|
292
|
+
Rub2.putlog "#{job_id}(#{host}) => #{exit_code}\t[#{min}m#{sec.truncate}s]\t(#{@success_count}/#{@job_count})"
|
279
293
|
end
|
280
294
|
end
|
281
295
|
|
@@ -292,7 +306,6 @@ EOS
|
|
292
306
|
# execute_with array (, arrays) do |arg1 (, args...)|
|
293
307
|
# return command_string
|
294
308
|
# end
|
295
|
-
|
296
309
|
def execute_with(first, *rest, &block)
|
297
310
|
commands = []
|
298
311
|
first.zip(*rest) do |i|
|
@@ -345,6 +358,10 @@ EOS
|
|
345
358
|
@script.inherit_environment = true
|
346
359
|
end
|
347
360
|
|
361
|
+
def queue(q)
|
362
|
+
@script.queue = q
|
363
|
+
end
|
364
|
+
|
348
365
|
def continue_on_error
|
349
366
|
@continue_on_error = true
|
350
367
|
end
|
@@ -370,11 +387,16 @@ EOS
|
|
370
387
|
|
371
388
|
@script.build
|
372
389
|
|
373
|
-
|
374
390
|
if @dry_run
|
375
391
|
puts @script.source
|
376
392
|
return
|
377
393
|
end
|
394
|
+
|
395
|
+
if @script.commands.empty?
|
396
|
+
raise "Empty commands"
|
397
|
+
return
|
398
|
+
end
|
399
|
+
|
378
400
|
@jobid << submit_qsub(@script.source)
|
379
401
|
@job_store.init_job(@jobid.first, @script.array_request, @max_retry_count)
|
380
402
|
end
|
@@ -398,7 +420,7 @@ EOS
|
|
398
420
|
else
|
399
421
|
results.each do |aid, ret|
|
400
422
|
unless ret == 0
|
401
|
-
Rub2.putlog "array job failed: #{ret}"
|
423
|
+
Rub2.putlog "array job[#{aid}] failed: #{ret}"
|
402
424
|
end
|
403
425
|
end
|
404
426
|
end
|
@@ -451,7 +473,7 @@ EOS
|
|
451
473
|
end
|
452
474
|
jobid =~ /\A(\d+)/
|
453
475
|
jobid = $1
|
454
|
-
Rub2.putlog "job submited: #{jobid}[#{array_option || @script.make_array_request_string}]"
|
476
|
+
Rub2.putlog "job submited: #{@script.name} -> #{jobid}[#{array_option || @script.make_array_request_string}]"
|
455
477
|
return jobid
|
456
478
|
end
|
457
479
|
|
@@ -463,7 +485,6 @@ EOS
|
|
463
485
|
Rub2.putlog "start Rinda Server: #{@uri}"
|
464
486
|
return @uri
|
465
487
|
end
|
466
|
-
|
467
488
|
end
|
468
489
|
end
|
469
490
|
|
@@ -471,7 +492,7 @@ end
|
|
471
492
|
def submit(name, &block)
|
472
493
|
raise "Empty name" if name.empty?
|
473
494
|
job = Rub2::Manager.new(name)
|
474
|
-
job.
|
495
|
+
job.instance_exec(name, &block)
|
475
496
|
job.submit
|
476
497
|
return job.wait_finish
|
477
498
|
end
|
data/lib/rub2/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rub2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- holrock
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-09-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -48,7 +48,7 @@ files:
|
|
48
48
|
- ".gitignore"
|
49
49
|
- Gemfile
|
50
50
|
- LICENSE.txt
|
51
|
-
- README.
|
51
|
+
- README.md
|
52
52
|
- Rakefile
|
53
53
|
- lib/rub2.rb
|
54
54
|
- lib/rub2/version.rb
|
@@ -73,8 +73,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
73
73
|
- !ruby/object:Gem::Version
|
74
74
|
version: '0'
|
75
75
|
requirements: []
|
76
|
-
|
77
|
-
rubygems_version: 2.6.14
|
76
|
+
rubygems_version: 3.0.3
|
78
77
|
signing_key:
|
79
78
|
specification_version: 4
|
80
79
|
summary: simple DSL for submitting jobs via qsub
|