chore 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/lib/chore/server.rb CHANGED
@@ -2,6 +2,7 @@ require 'eventmachine'
2
2
  require 'evma_httpserver'
3
3
  require 'chore/store'
4
4
  require 'json'
5
+ require 'erb'
5
6
 
6
7
  # Process submissions from a client and save it in the store.
7
8
  module ChoreCollect
@@ -62,39 +63,9 @@ class ChoreWeb < EventMachine::Connection
62
63
 
63
64
  def process_http_request
64
65
  resp = EventMachine::DelegatedHttpResponse.new(self)
65
-
66
- html = <<-html
67
- <html>
68
- <head>
69
- <style type="text/css">
70
- body {font-family:monospace;background-color:#CCCCCC;}
71
- .red {color:red;}
72
- .yellow {color:yellow;}
73
- .green {color:green;}
74
- table, th, td { border: 1px solid black;}
75
- </style>
76
- <meta http-equiv="refresh" content="60">
77
- </head>
78
- <body>
79
- <h1>Chores</h1>
80
- <p>Last updated #{Time.now}</p>
81
- <table>
82
- <tr><th>Job</th><th>Status</th><th>Time</th><th>Notes</th></tr>
83
- html
84
-
85
- Chore::Store.iterate_statuses do |status|
86
- row = "<tr class='#{status[:state]}'><td>#{status[:job]}</td><td>#{status[:status]}ed</td><td>#{Time.at(status[:start_time])}</td>"
87
- if !status[:notes].empty?
88
- row += "<td>(#{status[:notes].join(', ')})</td>"
89
- else
90
- row += "<td>&nbsp;</td>"
91
- end
92
-
93
- row += "</tr>\n"
94
- html << row
95
- end
96
-
97
- html << "</body></html>"
66
+ filepath = File.dirname(__FILE__) + '/../../views/status.rhtml'
67
+ markup = File.open(filepath).read
68
+ html = ERB.new(markup).result
98
69
 
99
70
  resp.status = 200
100
71
  resp.content = html
data/lib/chore/store.rb CHANGED
@@ -74,62 +74,62 @@ module Chore
74
74
  end
75
75
 
76
76
  def self.build_status chore_name, status_info
77
- status = status_info['status'].to_sym
78
- run_time = status_info['start_time']
79
- run_time = 0 if !run_time
77
+ status = status_info['status'].to_sym
78
+ run_time = status_info['start_time']
79
+ run_time = 0 if !run_time
80
80
 
81
- current_time = Time.now.to_i
82
- do_every = status_info['do_every']
83
- grace_period = status_info['grace_period']
81
+ current_time = Time.now.to_i
82
+ do_every = status_info['do_every']
83
+ grace_period = status_info['grace_period']
84
84
 
85
- notes = []
86
- state = :red
85
+ notes = []
86
+ state = :red
87
87
 
88
- if status == :fail
88
+ if status == :fail
89
+ state = :red
90
+ if status_info['error']
91
+ notes << status_info['error']
92
+ else
93
+ notes << "FAILED!!!"
94
+ end
95
+
96
+ elsif status == :finish
97
+ finish_time = status_info['finish_time']
98
+ finish_in = status_info['finish_in']
99
+
100
+ if finish_in.nil?
101
+ state = :green
102
+ elsif (run_time + finish_in) >= finish_time
103
+ state = :green
104
+ else
89
105
  state = :red
90
- if status_info['error']
91
- notes << status_info['error']
92
- else
93
- notes << "FAILED!!!"
94
- end
95
-
96
- elsif status == :finish
97
- finish_time = status_info['finish_time']
98
- finish_in = status_info['finish_in']
99
-
100
- if finish_in.nil?
101
- state = :green
102
- elsif (run_time + finish_in) >= finish_time
103
- state = :green
104
- else
105
- state = :red
106
- notes << "Finished, but #{finish_time - (run_time + finish_in)} seconds late!!!"
107
- end
108
- elsif status == :start || status == :status_update
109
- if do_every
110
- if run_time + do_every >= current_time
111
- state = :green
112
- notes << "Should run every #{Chore::TimeHelp.elapsed_human_time(do_every)}"
113
- elsif grace_period && run_time + do_every + grace_period > current_time
114
- state = :yellow
115
- notes << "Job should run every #{Chore::TimeHelp.elapsed_human_time(do_every)}, but has a grace period of #{Chore::TimeHelp.elapsed_human_time(grace_period)}"
116
- else
117
- state = :red
118
- notes << "Job should run every #{Chore::TimeHelp.elapsed_human_time(do_every)}, but hasn't run since #{Time.at(run_time)}"
119
- end
120
- else
121
- state = :green
122
- end
106
+ notes << "Finished, but #{finish_time - (run_time + finish_in)} seconds late!!!"
107
+ end
108
+ elsif status == :start || status == :status_update
109
+ state = :green
123
110
 
124
- if status_info['expire_in']
125
- expire_in = Time.at(status_info['start_time'] + status_info['expire_in'].to_i)
126
- notes << "Will expire in #{expire_in}"
127
- end
111
+ if status_info['expire_in']
112
+ expire_in = Time.at(status_info['start_time'] + status_info['expire_in'].to_i)
113
+ notes << "Will expire in #{expire_in}"
114
+ end
128
115
 
129
- notes << "Status: #{status_info['status_note']}" if status_info['status_note']
116
+ notes << "Status: #{status_info['status_note']}" if status_info['status_note']
117
+ end
118
+
119
+ if do_every
120
+ if run_time + do_every >= current_time
121
+ notes << "Should run every #{Chore::TimeHelp.elapsed_human_time(do_every)}"
122
+ elsif grace_period && run_time + do_every + grace_period > current_time
123
+ state = :yellow unless state == :red
124
+ notes << "Job should run every #{Chore::TimeHelp.elapsed_human_time(do_every)}, but has a grace period of #{Chore::TimeHelp.elapsed_human_time(grace_period)}"
125
+ else
126
+ state = :red
127
+ notes << "Job should run every #{Chore::TimeHelp.elapsed_human_time(do_every)}, but hasn't run since #{Time.at(run_time)}"
130
128
  end
131
-
132
- info = {:job => chore_name, :state => state, :status => status, :start_time => run_time, :notes => notes}
129
+ end
130
+
131
+
132
+ info = {:job => chore_name, :state => state, :status => status, :start_time => run_time, :notes => notes}
133
133
  end
134
134
 
135
135
 
@@ -0,0 +1,42 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <style type="text/css">
5
+ body {font-family:monospace;background-color:#CCCCCC;}
6
+ .red {color:red;}
7
+ .yellow {color:yellow;}
8
+ .green {color:green;}
9
+ table, th, td { border: 1px solid black;}
10
+ </style>
11
+ <title>Chore Server</title>
12
+
13
+ <meta http-equiv="refresh" content="60">
14
+ </head>
15
+
16
+ <body>
17
+ <h1>Chores</h1>
18
+ <p>Last updated <%= Time.now %></p>
19
+ <table>
20
+ <tr>
21
+ <th>Job</th>
22
+ <th>Status</th>
23
+ <th>Time</th>
24
+ <th>Notes</th>
25
+ </tr>
26
+ <% Chore::Store.iterate_statuses do |status| %>
27
+ <tr class="<%= status[:state] %>">
28
+ <td><%= status[:job] %></td>
29
+ <td><%= status[:status] %>ed</td>
30
+ <td><%= Time.at(status[:start_time]) %></td>
31
+ <td>
32
+ <% if !status[:notes].empty? %>
33
+ <%= status[:notes].join(', ') %>
34
+ <% else %>
35
+ &nbsp;
36
+ <% end %>
37
+ </td>
38
+ </tr>
39
+ <% end %>
40
+ </table>
41
+ </body>
42
+ </html>
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: chore
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.2
5
+ version: 0.2.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Pikimal, LLC
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2012-07-03 00:00:00 Z
13
+ date: 2012-09-21 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: eventmachine
@@ -72,6 +72,7 @@ files:
72
72
  - lib/chore/time_help.rb
73
73
  - lib/chore/store.rb
74
74
  - lib/chore/constants.rb
75
+ - views/status.rhtml
75
76
  - bin/chore-server
76
77
  - bin/chore-status
77
78
  - bin/chore-client
@@ -98,7 +99,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
98
99
  requirements: []
99
100
 
100
101
  rubyforge_project:
101
- rubygems_version: 1.8.11
102
+ rubygems_version: 1.8.24
102
103
  signing_key:
103
104
  specification_version: 3
104
105
  summary: Monitor recurring chores