rukawa 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cd835345eb1c1841c6dd7d6a907287eea0e359d6
4
- data.tar.gz: 48eecf5784e84b8061edc309a657458567ea0743
3
+ metadata.gz: 3708a96687aab4647f068cda298ad49619ae352d
4
+ data.tar.gz: 27ac524cfb1eeb05a479e93e6f433a17a6498842
5
5
  SHA512:
6
- metadata.gz: 07caf395ab5d616dc6803fbb6da39465465aaa6bf295900792c4643721328b5f531abfe3b3e01a31dc8853aa4e11e7b19fdf254177ae8112ee2d8b0a66a723ba
7
- data.tar.gz: 1b77d69131e8fc808294a7ef2e814b649c995a56a78e8422d6866127ad9bd229b9137ab4dea8a3bc645d4c05b885e5e7a2d0952d06731d3e9804d5cfa309c36b
6
+ metadata.gz: ad83b7c946d04cccfee6e16b3ac6b30d7421e361ece92287d0de503f380d1c9bda1e88b087f750b8cb994f0aca007e113008d028110f2ef959073277ef0fcd7a
7
+ data.tar.gz: 51aae209a567c73ce9fa031e91423c37facd25f93829d1c08a1467b73561d238a4fbbe9f56f3d85718d1586d57309d3ab5cac0cc2dfcba0afad0faef56a2f087
@@ -42,15 +42,16 @@ module Rukawa
42
42
  end
43
43
 
44
44
  def formatted_elapsed_time_from(time = Time.now)
45
- sec = elapsed_time_from(time)
46
- return "N/A" unless sec
45
+ elapsed = elapsed_time_from(time)
46
+ return "N/A" unless elapsed
47
47
 
48
- hour = sec.to_i / 3600
49
- min = sec.to_i / 60
48
+ hour = elapsed.to_i / 3600
49
+ min = elapsed.to_i / 60
50
+ sec = (elapsed - hour * 3600 - min * 60).to_i
50
51
 
51
52
  hour_format = min > 0 ? "%dh " % hour : ""
52
53
  min_format = min > 0 ? "%dm " % min : ""
53
- sec_format = "#{sec.to_i}s"
54
+ sec_format = "#{sec}s"
54
55
  "#{hour_format}#{min_format}#{sec_format}"
55
56
  end
56
57
  end
data/lib/rukawa/dag.rb CHANGED
@@ -11,6 +11,7 @@ module Rukawa
11
11
  def initialize
12
12
  @nodes = Set.new
13
13
  @jobs = Set.new
14
+ @start_jobs = Set.new
14
15
  @edges = Set.new
15
16
  end
16
17
 
@@ -21,6 +22,7 @@ module Rukawa
21
22
  job = job_class.new(job_net)
22
23
  @nodes << job
23
24
  @jobs << job if job.is_a?(Job)
25
+ @start_jobs << job if job.is_a?(Job) && dependencies[job_class].empty?
24
26
 
25
27
  dependencies[job_class].each do |depend_job_class|
26
28
  depend_job = @nodes.find { |j| j.instance_of?(depend_job_class) }
@@ -67,6 +69,32 @@ module Rukawa
67
69
  end
68
70
  end
69
71
 
72
+ def leveled_each
73
+ visited = Set.new
74
+ queue = []
75
+ queue.push(*@start_jobs)
76
+
77
+ if block_given?
78
+ until queue.empty?
79
+ next_job = queue.shift
80
+ yield next_job unless visited.include?(next_job)
81
+ queue.push(*next_job.out_goings.map(&:to)) if visited.add?(next_job)
82
+ end
83
+ else
84
+ Enumerator.new do |y|
85
+ until queue.empty?
86
+ next_job = queue.shift
87
+ y << next_job unless visited.include?(next_job)
88
+ queue.push(*next_job.out_goings.map(&:to)) if visited.add?(next_job)
89
+ end
90
+ end
91
+ end
92
+ end
93
+
94
+ def start_jobs
95
+ @start_jobs
96
+ end
97
+
70
98
  private
71
99
 
72
100
  def tsortable_hash(hash)
@@ -49,7 +49,7 @@ module Rukawa
49
49
  end
50
50
 
51
51
  def dataflows
52
- @dag.tsort.reverse.map(&:dataflow)
52
+ @dag.leveled_each.map(&:dataflow)
53
53
  end
54
54
 
55
55
  def state
@@ -1,3 +1,3 @@
1
1
  module Rukawa
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rukawa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - joker1007