redact 0.1.3 → 0.1.4

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
2
  SHA1:
3
- metadata.gz: 9f859024a006575309d7d616e5a1c996e5c1e79c
4
- data.tar.gz: 6ef60e3ad77160e2d22a1d538f71f10be6043962
3
+ metadata.gz: 35e086f4ccb38a982329db34080c075ad21811d0
4
+ data.tar.gz: 7a7d7951f84eca27e693396cc97b6856465f2185
5
5
  SHA512:
6
- metadata.gz: 68805e7ee55892d4898e57ee98fb51307297090b7b4de6d444c98f21c05a3e388cb301b54bd6394e2ef3accf4594f5dc46f38f439836b143dcf6e5245b7b5ba5
7
- data.tar.gz: 77ad7358b7ce73b0f90397c4fbf4a69842f2d1bdeeba74fa1346241e005c7ac17b594cfbd74d6832635e4ef6e25bb9732a62eedc48a6dd526a1428da9d0944a6
6
+ metadata.gz: 10146d81cc2d500cf314423236d8ab9b8efdccd15c1ee2ce2521633a77403bd06b5b1dbc0ad152146a38c4f02da3d73226feaea9632befdb276ce4e25a3fc3f4
7
+ data.tar.gz: bfd307a4d1c16b5da34a0be4ceece363ff7f7a53ba707da0f2473f13a68cbe5f588e788a990e575777eba5daaf43d4067a2f5e7d1ef84abcc6d07cfc3f36aae1
@@ -5,6 +5,7 @@ require 'redis'
5
5
  require "redact"
6
6
  require 'sinatra/base'
7
7
  require 'ostruct'
8
+ require 'json'
8
9
 
9
10
  class Server < Sinatra::Base
10
11
  def initialize redact
@@ -13,25 +14,33 @@ class Server < Sinatra::Base
13
14
  end
14
15
 
15
16
  get '/' do
16
- enqueued = @redact.enqueued_tasks.map { |t| OpenStruct.new t }
17
- in_progress = @redact.in_progress_tasks.map { |t| OpenStruct.new t }
18
- done = @redact.done_tasks.map { |t| OpenStruct.new t }
17
+ enqueued = @redact.enqueued_tasks(0, 10).map { |t| OpenStruct.new t }
18
+ in_progress = @redact.in_progress_tasks(0, 10).map { |t| OpenStruct.new t }
19
+ done = @redact.done_tasks(0, 10).map { |t| OpenStruct.new t }
19
20
 
20
21
  (enqueued + in_progress + done).each do |x|
21
22
  x.ago = pretty_time_diff((Time.now - x.ts).abs)
22
23
  x.time_in_queue = x.time_waiting ? pretty_time_diff(x.time_waiting.to_i) : ""
23
24
  x.time_in_progress = x.time_processing ? pretty_time_diff(x.time_processing.to_i) : ""
24
- x.params = x.params.map { |k, v| "<b>#{k}</b>: #{v}<br/>" }.join
25
+ x.params = (x.params || {}).map { |k, v| "<b>#{k}</b>: #{v}<br/>" }.join
26
+ x.send "error?=", (x.state == "error")
27
+ x.backtrace_html = JSON.parse(x.backtrace).map { |x| Rack::Utils.escape_html(x) }.join("<br/>") if x.backtrace
25
28
  x.state_happiness = case x.state
26
29
  when "done"; "success"
27
30
  when "error"; "danger"
28
31
  when "skipped"; "warning"
29
32
  when "in_progress"; x.tries > 0 ? "warning" : ""
30
33
  end
31
-
32
34
  end
33
35
 
34
- erb :index, locals: { enqueued: enqueued, in_progress: in_progress, done: done }
36
+ erb :index, locals: {
37
+ enqueued: enqueued,
38
+ in_progress: in_progress,
39
+ done: done,
40
+ num_enqueued: @redact.num_enqueued_tasks,
41
+ num_in_progress: @redact.num_in_progress_tasks,
42
+ num_done: @redact.num_done_tasks,
43
+ }
35
44
  end
36
45
 
37
46
  def pretty_time_diff diff
@@ -33,6 +33,8 @@ class Redact
33
33
  @params_key = [@namespace, "params"].join
34
34
  end
35
35
 
36
+ attr_reader :dag
37
+
36
38
  ## Drop all data and reset the planner.
37
39
  def reset!
38
40
  keys = [@queue, @processing_list, @done_list, @dag_key, @params_key]
@@ -40,6 +42,21 @@ class Redact
40
42
  keys.each { |k| @redis.del k }
41
43
  end
42
44
 
45
+ def visualize stream=$stdout
46
+ sorted = @dag.tsort
47
+ leaves = sorted.select { |k| @dag[k].nil? || @dag[k].empty? }
48
+
49
+ pos = {}
50
+ curpos = 0
51
+ leaves.each do |l|
52
+ string = " #{l} "
53
+ pos[l] = curpos
54
+ stream.print string
55
+ curpos += string.length
56
+ end
57
+ stream.puts
58
+ end
59
+
43
60
  class CyclicDependencyError < StandardError; end
44
61
 
45
62
  ## Add a task with dependencies. +What+ is the name of a task (either a symbol
@@ -117,6 +134,7 @@ class Redact
117
134
  def enqueued_tasks start_idx=0, end_idx=-1
118
135
  @redis.lrange(@queue, start_idx, end_idx).map { |t| task_summary_for t }
119
136
  end
137
+ def num_enqueued_tasks; @redis.llen @queue end
120
138
 
121
139
  ## Returns information representing the set of tasks currently in process by
122
140
  ## worker processes. The return value is a hash that includes keys from
@@ -127,6 +145,7 @@ class Redact
127
145
  def in_progress_tasks start_idx=0, end_idx=-1
128
146
  @redis.lrange(@processing_list, start_idx, end_idx).map { |t| task_summary_for t }
129
147
  end
148
+ def num_in_progress_tasks; @redis.llen @processing_list end
130
149
 
131
150
  ## Returns information representing the set of tasks that have been
132
151
  ## completed. The return value is a hash that includes keys from
@@ -140,6 +159,7 @@ class Redact
140
159
  def done_tasks start_idx=0, end_idx=-1
141
160
  @redis.lrange(@done_list, start_idx, end_idx).map { |t| task_summary_for t }
142
161
  end
162
+ def num_done_tasks; @redis.llen @done_list end
143
163
 
144
164
  ## Yields tasks from the queue that are ready for execution. Callers should
145
165
  ## then perform the work for those tasks. Any exceptions thrown will result in the
@@ -7,7 +7,7 @@
7
7
  </head>
8
8
 
9
9
  <body>
10
- <h1>In Progress (<%= in_progress.size %>)</h1>
10
+ <h1>In Progress (<%= num_in_progress %>)</h1>
11
11
 
12
12
  <div class="table-responsive">
13
13
  <table class="table table-striped table-hover table-condensed">
@@ -36,7 +36,7 @@
36
36
  </table>
37
37
  </div>
38
38
 
39
- <h1>Enqueued (<%= enqueued.size %>)</h1>
39
+ <h1>Enqueued (<%= num_enqueued %>)</h1>
40
40
 
41
41
  <div class="table-responsive">
42
42
  <table class="table table-striped table-hover table-condensed">
@@ -65,7 +65,7 @@
65
65
  </table>
66
66
  </div>
67
67
 
68
- <h1>Recently completed (<%= done.size %>)</h1>
68
+ <h1>Recently completed (<%= num_done %>)</h1>
69
69
 
70
70
  <div class="table-responsive">
71
71
  <table class="table table-striped table-hover table-condensed">
@@ -83,7 +83,15 @@
83
83
  <tbody>
84
84
  <% done.each do |t| %>
85
85
  <tr class="<%= t.state_happiness %>">
86
- <td><%= t.task %><br/><%= t.target %><br/><%= t.worker_id %></td>
86
+ <td>
87
+ <%= t.task %><br/>
88
+ <%= t.target %><br/>
89
+ <%= t.worker_id %><br/>
90
+ <% if t.error? %>
91
+ <b><%= t.error %></b><br/>
92
+ <%= t.backtrace_html %>
93
+ <% end %>
94
+ </td>
87
95
  <td><%= t.run_id %></td>
88
96
  <td><%= t.ago %></td>
89
97
  <td><%= t.state %></td>
@@ -91,6 +99,7 @@
91
99
  <td><%= t.time_in_progress %></td>
92
100
  <td><%= t.params %></td>
93
101
  </tr>
102
+
94
103
  <% end %>
95
104
  </tbody>
96
105
  </table>
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: redact
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - William Morgan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-09 00:00:00.000000000 Z
11
+ date: 2014-10-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: trollop