Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions lib/qless/queue.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ def running(start = 0, count = 25)
@client.call('jobs', 'running', @name, start, count)
end

def throttled(start = 0, count = 25)
@client.call('jobs', 'throttled', @name, start, count)
end

def stalled(start = 0, count = 25)
@client.call('jobs', 'stalled', @name, start, count)
end
Expand Down
2 changes: 1 addition & 1 deletion lib/qless/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ def strftime(t)
json(client.queues[params[:name]].counts)
end

filtered_tabs = %w[ running scheduled stalled depends recurring ].to_set
filtered_tabs = %w[ running throttled scheduled stalled depends recurring ].to_set
get '/queues/:name/?:tab?' do
queue = client.queues[params[:name]]
tab = params.fetch('tab', 'stats')
Expand Down
6 changes: 4 additions & 2 deletions lib/qless/server/views/queue.erb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
<li class="<%= tab == 'stats' ? 'active' : '' %>"><a href="<%= u "/queues/#{CGI::escape(queue['name'])}/stats" %>">Stats</a></li>
<li class="<%= tab == 'running' ? 'active' : '' %>"><a href="<%= u "/queues/#{CGI::escape(queue['name'])}/running" %>">Running</a></li>
<li class="<%= tab == 'waiting' ? 'active' : '' %>"><a href="<%= u "/queues/#{CGI::escape(queue['name'])}/waiting" %>">Waiting</a></li>
<li class="<%= tab == 'throttled' ? 'active' : '' %>"><a href="<%= u "/queues/#{CGI::escape(queue['name'])}/throttled" %>">Throttled</a></li>
<li class="<%= tab == 'scheduled' ? 'active' : '' %>"><a href="<%= u "/queues/#{CGI::escape(queue['name'])}/scheduled" %>">Scheduled</a></li>
<li class="<%= tab == 'stalled' ? 'active' : '' %>"><a href="<%= u "/queues/#{CGI::escape(queue['name'])}/stalled" %>">Stalled</a></li>
<li class="<%= tab == 'depends' ? 'active' : '' %>"><a href="<%= u "/queues/#{CGI::escape(queue['name'])}/depends" %>">Depends</a></li>
Expand All @@ -57,9 +58,10 @@
<h2><a href="<%= u "/queues/#{CGI::escape(queue['name'])}" %>"><%= queue['name'] %></a> |
<%= queue['running'] %> /
<%= queue['waiting'] %> /
<%= queue['throttled'] %> /
<%= queue['scheduled'] %> /
<%= queue['stalled'] %> /
<%= queue['depends'] %> <small>(running / waiting / scheduled / stalled / depends)</small>
<%= queue['depends'] %> <small>(running / waiting / throttled / scheduled / stalled / depends)</small>
</h2>
</div>

Expand All @@ -74,7 +76,7 @@
</div>
</div>

<% if ['running', 'waiting', 'scheduled', 'stalled', 'depends', 'recurring'].include?(tab) %>
<% if ['running', 'waiting', 'throttled', 'scheduled', 'stalled', 'depends', 'recurring'].include?(tab) %>
<hr/>
<%= erb :_job_list, :locals => { :jobs => jobs, :queues => queues } %>
<% else %>
Expand Down
4 changes: 3 additions & 1 deletion lib/qless/server/views/queues.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,11 @@
<h3> |
<%= queue['running'] %> /
<%= queue['waiting'] %> /
<%= queue['throttled'] %> /
<%= queue['scheduled'] %> /
<%= queue['stalled'] %> /
<%= queue['depends'] %> <small>(running / waiting / scheduled / stalled / depends)</small>
<%= queue['depends'] %> /
<%= queue['recurring'] %> <small>(running / waiting / throttled / scheduled / stalled / depends / recurring)</small>
</h3>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions lib/qless/server/views/track.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ var fade = function(jid, type) {
<li class="active"><a href="#all" data-toggle="tab">All (<%= tracked['jobs'].length %>)</a></li>
<li><a href="#running" data-toggle="tab">Running (<%= tracked['jobs'].select { |job| job.state == 'running' }.length %>)</a></li>
<li><a href="#waiting" data-toggle="tab">Waiting (<%= tracked['jobs'].select { |job| job.state == 'waiting' }.length %>)</a></li>
<li><a href="#throttled" data-toggle="tab">Throttled (<%= tracked['jobs'].select { |job| job.state == 'throttled'}.length %>)</a></li>
<li><a href="#scheduled" data-toggle="tab">Scheduled (<%= tracked['jobs'].select { |job| job.state == 'scheduled' }.length %>)</a></li>
<li><a href="#stalled" data-toggle="tab">Stalled (<%= tracked['jobs'].select { |job| job.state == 'stalled' }.length %>)</a></li>
<li><a href="#completed" data-toggle="tab">Completed (<%= tracked['jobs'].select { |job| job.state == 'complete' }.length %>)</a></li>
Expand Down Expand Up @@ -41,6 +42,11 @@ var fade = function(jid, type) {
<%= erb :_job, :layout => false, :locals => { :job => job, :queues => queues } %>
<% end %>
</div>
<div class="tab-pane" id="throttled">
<% tracked['jobs'].select { |job| job.state == 'throttled' }.each do |job| %>
<%= erb :_job, :layout => false, :locals => { :job => job, :queues => queues } %>
<% end %>
</div>
<div class="tab-pane" id="scheduled">
<% tracked['jobs'].select { |job| job.state == 'scheduled' }.each do |job| %>
<%= erb :_job, :layout => false, :locals => { :job => job, :queues => queues } %>
Expand Down
98 changes: 93 additions & 5 deletions spec/integration/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,23 +134,34 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)
q.put(Qless::Job, {})
visit '/'
first('.queue-row', text: /testing/).should be
first('.queue-row', text: /0\D+1\D+0\D+0\D+0/).should be
first('.queue-row', text: /0\D+1\D+0\D+0\D+0\D+0\D+0/).should be
first('h1', text: /no queues/i).should be_nil
first('h1', text: /queues and their job counts/i).should be

# Let's pop the job, and make sure that we can see /that/
job = q.pop
visit '/'
first('.queue-row', text: /1\D+0\D+0\D+0\D+0/).should be
first('.queue-row', text: /1\D+0\D+0\D+0\D+0\D+0\D+0/).should be
first('.worker-row', text: q.worker_name).should be
first('.worker-row', text: /1\D+0/i).should be

# Let's complete the job, and make sure it disappears
job.complete
visit '/'
first('.queue-row', text: /0\D+0\D+0\D+0\D+0/).should be
first('.queue-row', text: /0\D+0\D+0\D+0\D+0\D+0\D+0/).should be
first('.worker-row', text: /0\D+0/i).should be

# Let's throttle a job, and make sure we see it
client.throttles['one'].maximum = 1
q.put(Qless::Job, {}, :throttles => ["one"])
q.put(Qless::Job, {}, :throttles => ["one"])
job1 = q.pop
job2 = q.pop
visit '/'
first('.queue-row', text: /1\D+0\D+1\D+0\D+0\D+0\D+0/).should be
job1.complete
q.pop.complete

# Let's put and pop and fail a job, and make sure we see it
q.put(Qless::Job, {})
job = q.pop
Expand All @@ -162,11 +173,11 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)
# And let's have one scheduled, and make sure it shows up accordingly
jid = q.put(Qless::Job, {}, delay: 60)
visit '/'
first('.queue-row', text: /0\D+0\D+1\D+0\D+0/).should be
first('.queue-row', text: /0\D+0\D+0\D+1\D+0\D+0\D+0/).should be
# And one that depends on that job
q.put(Qless::Job, {}, depends: [jid])
visit '/'
first('.queue-row', text: /0\D+0\D+1\D+0\D+1/).should be
first('.queue-row', text: /0\D+0\D+0\D+1\D+0\D+1\D+0/).should be
end

it 'can visit the tracked page' do
Expand All @@ -193,6 +204,17 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)
first('a', text: /completed\W+1/i).should be
job.untrack

# And now for a throttled job
client.throttles['one'].maximum = 1
q.put(Qless::Job, {}, throttles: ["one"])
job = client.jobs[q.put(Qless::Job, {}, throttles: ["one"])]
job.track
q.pop(2)
visit '/track'
first('a', text: /all\W+1/i).should be
first('a', text: /throttled\W+1/i).should be
job.untrack

# And now for a scheduled job
job = client.jobs[q.put(Qless::Job, {}, delay: 600)]
job.track
Expand Down Expand Up @@ -634,6 +656,52 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)
groups.map { |g| g.text }.join(' ').should eq('e j i h g f d c b a')
end

it 'can visit /queues' do
# We should be able to see all of the appropriate tabs,
# We should be able to see all of the jobs
jid = q.put(Qless::Job, {})

# We should see this job
visit '/queues'
first('h3', text: /0\D+1\D+0\D+0\D+0\D+0\D+0/).should be

# Now let's pop off the job so that it's running
job = q.pop
visit '/queues'
first('h3', text: /1\D+0\D+0\D+0\D+0\D+0\D+0/).should be
job.complete

# And now for a throttled job
client.throttles['one'].maximum = 1
q.put(Qless::Job, {}, throttles: ["one"])
q.put(Qless::Job, {}, throttles: ["one"])
job1, job2 = q.pop(2)
visit '/queues'
first('h3', text: /1\D+0\D+1\D+0\D+0\D+0\D+0/).should be
job1.complete
q.pop.complete

# And now for a scheduled job
job = client.jobs[q.put(Qless::Job, {}, delay: 600)]
visit '/queues'
first('h3', text: /0\D+0\D+0\D+1\D+0\D+0\D+0/).should be
job.cancel

# And now a dependent job
job1 = client.jobs[q.put(Qless::Job, {})]
job2 = client.jobs[q.put(Qless::Job, {}, depends: [job1.jid])]
visit '/queues'
first('h3', text: /0\D+1\D+0\D+0\D+0\D+1\D+0/).should be
job2.cancel
job1.cancel

# And now a recurring job
job = client.jobs[q.recur(Qless::Job, {}, 5)]
visit '/queues'
first('h3', text: /0\D+0\D+0\D+0\D+0\D+0\D+1/).should be
job.cancel
end

it 'can visit the various /queues/* endpoints' do
# We should be able to see all of the appropriate tabs,
# We should be able to see all of the jobs
Expand All @@ -648,6 +716,16 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)
first('h2', text: /#{jid[0...8]}/).should be
job.complete

# And now for a throttled job
client.throttles['one'].maximum = 1
job1 = client.jobs[q.put(Qless::Job, {}, throttles: ["one"])]
job2 = client.jobs[q.put(Qless::Job, {}, throttles: ["one"])]
q.pop(2)
visit '/queues/testing/throttled'
first('h2', text: /#{job2.jid[0...8]}/).should be
job1.cancel
job2.cancel

# And now for a scheduled job
job = client.jobs[q.put(Qless::Job, {}, delay: 600)]
visit '/queues/testing/scheduled'
Expand Down Expand Up @@ -690,6 +768,16 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)
job.untrack
first('.tracked-row', text: /complete/i).should be

# And now for a throttled job
client.throttles['one'].maximum = 1
job1 = client.jobs[q.put(Qless::Job, {}, throttles: ["one"])]
job2 = client.jobs[q.put(Qless::Job, {}, throttles: ["one"])]
job2.track
q.pop(2)
visit '/'
first('.tracked-row', text: /throttled/i).should be
job2.untrack

# And now for a scheduled job
job = client.jobs[q.put(Qless::Job, {}, delay: 600)]
job.track
Expand Down