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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3076d25cda3711a25aa2affcb5d6e6910116d22c
4
- data.tar.gz: 1dae4fdf67c4c12d4fe6ffd5497b1cd4003d88d1
2
+ SHA256:
3
+ metadata.gz: f3c4e11450cfc56d7a6171bd2a59322cc927bb03d4680519cbfce7fcf61a7bf8
4
+ data.tar.gz: 676b2f0326d75c31e760547e81df36f154036d42133c78baadecf0908ee78281
5
5
  SHA512:
6
- metadata.gz: 4fd9836ab51f32dfa84dfdf4a045bda69fd0886b9fc3e30a7ca34ae51145e27bc35970593584d5959d93266f952c3dd2cf9ebc7b4b523a888854f551046c22ed
7
- data.tar.gz: 14c99adaec23c336e8c8ed7f0e806d75bb459dbfde0c3b354b65b635d3f61d21128d821d251ad882ac27d6218f05d384e4d4508c6261ae0f4077ce7c2a3d176d
6
+ metadata.gz: f9be823b44ad553bf7f402d2639fcbe5a8bc7d8e913e02183fad46455996e341cbac23be3ed9567335314796e2fb807e100265893e411e8a8539d11674b2e417
7
+ data.tar.gz: 487085194ebfcc7b6f045f5de1e2bb393cf0c6dee34983423208654ad9805e4237a250342ab5bf798be60a8e11934d54e125308e07d9a1c84ea1d218e33b33cc
@@ -1,24 +1,32 @@
1
- * There's the rub
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 |dotfile|
11
- "wc -l #{dotfile}"
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 'log/test.log' # log file path
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
- ** log
61
+ ### log
53
62
 
54
63
  ログファイル出力先。未指定の場合はカレントフォルダにログディレクトリを作成します。
55
64
 
56
- ** resource
65
+ ### resource
57
66
 
58
67
  qsub -lオプション。リソース名 => 値のハッシュを渡してください。
59
68
 
60
- ** array_request
69
+ ### array_request
61
70
 
62
71
  実行するarray index。1-10の時は1..10のようにRangeを、1,2,4の時は[1,2,4]と配列を渡してください。
63
72
 
64
- ** inherit_environment
73
+ ### inherit_environment
65
74
 
66
75
  qsub -Vオプション。環境変数を引き継ぎます。
67
76
 
68
- ** dry_run
77
+ ### dry_run
69
78
 
70
79
  実行せずにsubmitするスクリプトを表示します。デバッグ向け。
71
80
 
72
- ** max_retry
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で終らせてくさい。
@@ -14,9 +14,16 @@ module Rub2
14
14
  module_function :putlog
15
15
 
16
16
  class JobScript
17
- attr_accessor :log, :shell, :resource, :array_request,
18
- :inherit_environment, :commands, :log_path, :uri
19
- attr_reader :source
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
- Rub2.putlog "#{job_id}(#{host}) => #{exit_code}\t(#{@success_count}/#{@job_count})"
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.instance_eval(&block)
495
+ job.instance_exec(name, &block)
475
496
  job.submit
476
497
  return job.wait_finish
477
498
  end
@@ -1,3 +1,3 @@
1
1
  module Rub2
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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.1.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: 2017-12-22 00:00:00.000000000 Z
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.txt
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
- rubyforge_project:
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