Skip to content

Commit

Permalink
Merge oper_status and admin_status. Break queue buttons out to a part…
Browse files Browse the repository at this point in the history
…ial.
  • Loading branch information
sodabrew committed Jul 16, 2014
1 parent b31fa3d commit 2ac4620
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 67 deletions.
21 changes: 8 additions & 13 deletions code/adminoper.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
module RQ
class AdminOper

attr_accessor :admin_status
attr_accessor :oper_status
attr_accessor :status

def initialize(pathname)
@pathname = pathname
Expand All @@ -13,18 +12,17 @@ def initialize(pathname)
@down_name = @dirname + "/" + @filename + ".down"
@pause_name = @dirname + "/" + @filename + ".pause"

@admin_status = "UNKNOWN"
@oper_status = "UNKNOWN"
@status = "UNKNOWN"
@daemon_status = "UP"
end

def update!
if File.exists?(@down_name)
@admin_status = @oper_status = "DOWN"
@status = "DOWN"
elsif File.exists?(@pause_name)
@admin_status = @oper_status = "PAUSE"
@status = "PAUSE"
else
@admin_status = @oper_status = "UP"
@status = "UP"
end
update_status
end
Expand All @@ -36,14 +34,11 @@ def set_daemon_status(stat)
update_status
end

private

def update_status
if @daemon_status == "UP"
@oper_status = @admin_status
else
@oper_status = @daemon_status
end
@status = @daemon_status if @daemon_status != "UP"
end
private :update_status

end
end
6 changes: 3 additions & 3 deletions code/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ def flash(type, msg)
throw :halt, [400, "400 - Invalid method param"]
end

if result == [ "fail", "oper_status: DOWN"]
if result == [ "fail", "status: DOWN"]
throw :halt, [503, "503 - Service Unavailable - Operationally Down"]
end

Expand Down Expand Up @@ -250,7 +250,7 @@ def flash(type, msg)
end

flash :notice, "Successfully #{action}d queue #{params[:name]}"
redirect back
redirect params[:back]
end

post '/q/:name/restart' do
Expand All @@ -264,7 +264,7 @@ def flash(type, msg)
end

flash :notice, "Successfully restarted queue #{params[:name]}"
redirect back
redirect params[:back]
end

get '/q/:name/config.json' do
Expand Down
5 changes: 2 additions & 3 deletions code/public/css/rq.css
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ h1 {font-size: 2.5em; margin-top: 0; margin-bottom: 2px; font-weight: bold;
#queue-status,
#message-actions {
float: right;
width: 300px;
text-align: right
}
.right {text-align: right}
Expand Down Expand Up @@ -182,12 +181,12 @@ form .note {
font-style: italic;
}

form.inline {
form.inrow {
padding: 0;
margin: 0;
}

form.inline button {
form.inrow button {
width: 5em;
}

Expand Down
18 changes: 9 additions & 9 deletions code/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,18 +260,18 @@ def run_queue_script!(msg)
script_path = Pathname.new(@config.script).realpath.to_s rescue @config.script
if (!File.executable?(script_path) rescue false)
log("ERROR - QUEUE SCRIPT - not there or runnable #{script_path}")
if @status.oper_status != 'SCRIPTERROR'
if @status.status != 'SCRIPTERROR'
@status.set_daemon_status('SCRIPTERROR')
log("SCRIPTERROR - DAEMON STATUS is set to SCRIPTERROR")
log("OPER STATUS is now: #{@status.oper_status}")
log("OPER STATUS is now: #{@status.status}")
end
return
end

if @status.oper_status == 'SCRIPTERROR'
if @status.status == 'SCRIPTERROR'
@status.set_daemon_status('UP')
log("SCRIPTERROR FIXED - DAEMON STATUS is set to UP")
log("OPER STATUS is now: #{@status.oper_status}")
log("OPER STATUS is now: #{@status.status}")
end

#log("0 child process prep step for runnable #{script_path}")
Expand Down Expand Up @@ -1225,7 +1225,7 @@ def run_scheduler!
@status.update!

# This could be DOWN, PAUSE, SCRIPTERROR
return unless @status.oper_status == 'UP'
return unless @status.status == 'UP'

# Are we arleady running max workers
active_count = @run.inject(0) do |acc, o|
Expand Down Expand Up @@ -1513,7 +1513,7 @@ def handle_request(sock)

when 'status'
@status.update!
resp = [ @status.admin_status, @status.oper_status ].to_json
resp = [ @status.status ].to_json
send_packet(sock, resp)
return

Expand All @@ -1524,10 +1524,10 @@ def handle_request(sock)
return
end

# IF queue is admin_status DOWN, no need to respond to any of the
# IF queue status is DOWN, no need to respond to any of the
# following messages (Note: there are other states, this is a hard DOWN)
if @status.admin_status == 'DOWN'
resp = [ "fail", "oper_status: DOWN"].to_json
if @status.status == 'DOWN'
resp = [ "fail", "status: DOWN"].to_json
send_packet(sock, resp)
return
end
Expand Down
5 changes: 4 additions & 1 deletion code/queueclient.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ def read_pid
end

PROTOCOL_MESSAGES = %w{
status
shutdown
num_messages
config
Expand Down Expand Up @@ -71,5 +70,9 @@ def uptime
send_recv('uptime').first
end

def status
send_recv('status').first
end

end
end
17 changes: 17 additions & 0 deletions code/views/_main_queue_form.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<form class="inline inrow" method="post" action="<%= "#{url}q/#{name}/adminoper" %>">
<input type="hidden" name="back" value="<%= request.path %>" />
<%- if status == 'PAUSE' -%>
<button id="resume-queue" name="resume" value="resume" <%= 'disabled="disabled"' if status == 'DOWN' %>>Resume</button>
<%- else -%>
<button id="pause-queue" name="pause" value="pause" <%= 'disabled="disabled"' if status == 'DOWN' %>>Pause</button>
<%- end -%>
<%- if status == 'DOWN' -%>
<button id="up-queue" name="up" value="up">Up</button>
<%- else -%>
<button id="down-queue" name="down" value="down">Down</button>
<%- end -%>
</form>
<form class="inline inrow" method="post" action="<%= "#{url}q/#{name}/restart" %>">
<input type="hidden" name="back" value="<%= request.path %>" />
<button id="restart-queue" name="restart" value="restart">Restart</button>
</form>
23 changes: 4 additions & 19 deletions code/views/_main_queue_row.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
<% begin
qc = get_queueclient(name)
raise unless qc.running?
admin_stat, oper_stat = qc.status
status = qc.status
-%>
<% if admin_stat != 'DOWN' -%>
<% if status != 'DOWN' -%>
<td><pre><%= msgs_labels.zip(qc.num_messages.values_at(*msgs_labels)).map{|ab| "#{ab[0]}:#{ab[1].to_s.ljust(4)} "}.join %></pre></td>
<% else -%>
<td>-</td>
Expand All @@ -14,8 +14,7 @@
<td><%= qc.read_pid %></td>
<td><%= qc.uptime %></td>
<td>
<span class="<%= admin_stat == 'UP' ? 'green' : 'red' %>"><%= admin_stat %></span>:
<span class="<%= oper_stat == 'UP' ? 'green' : 'red' %>"><%= oper_stat %></span>
<span class="<%= status == 'UP' ? 'green' : 'red' %>"><%= status %></span>
</td>
<% rescue -%>
<td>-</td>
Expand All @@ -25,20 +24,6 @@
<td><span class="red">DOWN <%= $! %></span></td>
<% end -%>
<td>
<form class="inline" method="post" action="<%= "#{url}q/#{name}/adminoper" %>">
<%- if admin_stat == 'PAUSE' -%>
<button id="resume-queue" name="resume" value="resume" <%= 'disabled="disabled"' if admin_stat == 'DOWN' %>>Resume</button>
<%- else -%>
<button id="pause-queue" name="pause" value="pause" <%= 'disabled="disabled"' if admin_stat == 'DOWN' %>>Pause</button>
<%- end -%>
<%- if admin_stat == 'DOWN' -%>
<button id="up-queue" name="up" value="up">Up</button>
<%- else -%>
<button id="down-queue" name="down" value="down">Down</button>
<%- end -%>
</form>
<form class="inline" method="post" action="<%= "#{url}q/#{name}/restart" %>">
<button id="restart-queue" name="restart" value="restart">Restart</button>
</form>
<%= erb :_main_queue_form, :locals => {:status => status, :url => url, :name => name } %>
</td>
</tr>
11 changes: 6 additions & 5 deletions code/views/queue.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,22 @@

<div id="sub-header">
<% if qc.running? %>
<% admin_status, oper_status = qc.status %>
<% status = qc.status %>
<div id="queue-status">
<p><span class="<%= admin_status == "UP" ? "green" : "red" %>"><%= admin_status %></span>:<span class="<%= oper_status == "UP" ? "green" : "red" %>"><%= oper_status %></span>
<span class="<%= status == "UP" ? "green" : "red" %>"><%= status %></span></span>
<span class=""> <%= qc.ping %></span>
<span class=""> <%= qc.read_pid %></span>
up for <%= qc.uptime %> seconds</p>
running for <%= qc.uptime %> seconds
<%= erb :_main_queue_form, :locals => {:status => status, :url => url, :name => qc.name } %>
<% else %>
<p>Status: <span class="red">queue is COMPLETELY DOWN</span></p>
Status: <span class="red">queue is COMPLETELY DOWN</span>
<% end %>
</div>
<p id="json-config">config.json [ <a href="#" onclick="show_toggle()">show/hide</a> | <a href="<%= "#{url}q/#{qc.name}/config.json" %>">raw</a> ]</p>
<pre id="config" class="json hidden"><%= JSON.pretty_generate(config) %></pre>
</div>

<% if %w{UP PAUSE}.include? admin_status %>
<% if status != 'DOWN' %>
<h2>Message List</h2>

<% num_msgs = qc.num_messages %>
Expand Down
23 changes: 12 additions & 11 deletions code/views/queue_json.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{<% status = qc.status %> "admin_status": "<%=status[0]%>"
,"oper_status": "<%=status[1]%>"
<% if status[1] != 'DOWN' %>
,"uptime": <%=qc.uptime%><% num_messages = qc.num_messages %>
,"prep_size": <%= num_messages['prep'] %>
,"que_size": <%= num_messages['que'] %>
,"run_size": <%= num_messages['run'] %>
,"done_size": <%= num_messages['done'] %>
,"err_size": <%= num_messages['err'] %>
,"relayed_size": <%= num_messages['relayed'] %>
<% end %>
<%- status = qc.status -%>
{"status":"<%= status -%>"
<%- if status != 'DOWN' -%>
,"uptime":<%= qc.uptime -%>
<%- num_messages = qc.num_messages -%>
,"prep_size":<%= num_messages['prep'] -%>
,"que_size":<%= num_messages['que'] -%>
,"run_size":<%= num_messages['run'] -%>
,"done_size":<%= num_messages['done'] -%>
,"err_size":<%= num_messages['err'] -%>
,"relayed_size":<%= num_messages['relayed'] -%>
<%- end -%>
}
5 changes: 2 additions & 3 deletions code/views/queue_txt.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<% status = qc.status %>
<%="admin_status: #{status[0]}"%>
<%="oper_status: #{status[1]}"%>
<% if status[1] != "DOWN" %>
<%="status: #{status}"%>
<% if status != "DOWN" %>
<%="uptime: #{qc.uptime}"%>

<% messages = qc.num_messages %>
Expand Down

0 comments on commit 2ac4620

Please sign in to comment.