Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,10 @@ def ttl
@expires_at - Time.now.to_f
end

def throttle_objects
throttles.map { |name| Throttle.new(name, client) }
end

def reconnect_to_redis
@client.redis.client.reconnect
end
Expand Down
32 changes: 27 additions & 5 deletions lib/qless/server/views/_job.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<div style="float:right; margin-top: 4px">
<div class="btn-group">
<% if (job.state != "complete") %>
<button title="delete" class="btn btn-danger" onclick="confirmation(this, 'Delete?', function() { cancel('<%= job.jid %>', fade) })"><i class="icon-remove"></i></button>
<button title="delete" class="btn btn-danger" onclick="confirmation(this, 'Delete?', function() { cancel('<%= job.jid %>', fade) })"><i class="icon-remove cancel-job"></i></button>
<% end %>
<% if (job.state == "running") %>
<button title="Time out job" class="btn btn-danger" onclick="confirmation(this, 'Time out job?', function() { timeout('<%= job.jid %>') })"><i class="icon-time"></i></button>
Expand Down Expand Up @@ -102,7 +102,7 @@
<button class="btn" onclick="tag('<%= job.jid %>', $(this).parent().siblings().val())">
<i class="icon-plus"></i>
</button>
</div>
</div>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you fubar the spacing again? =)

</div>
</div>

Expand Down Expand Up @@ -152,7 +152,29 @@
</div>
</div>
</div>
<% end %>
<% end %>

<% job.throttle_objects.each do |throttle| %>
<div class="row">
<div class="span4">
<h3><%= throttle.id %></h3>
</div>
<div class="span1">
<input class="span1 <%= throttle.id %>-maximum" type="text" placeholder="<%= throttle.maximum %>" onchange="update_throttle('<%= throttle.id %>', $(this).val())"></input>
</div>
<div class="span1" style="margin-left:10px">
<input class="span1 <%= throttle.id %>-expiration" type="text" placeholder="<%= throttle.ttl %>" onchange="expire_throttle('<%= throttle.id %>', $(this).val())"></input>
</div>
<div class="span1" style="margin-left:10px">
<button title="delete" class="btn btn-danger remove-throttle" onclick="confirmation(this, 'Delete?',function() { delete_throttle('<%= throttle.id %>', fade) })">
<i class="icon-remove"></i>
</button>
</div>
<div class="span3" style="margin-left:-20px">
<h3><small>( maximum / TTL / reset )</small></h3>
</div>
</div>
<% end %>
<hr/>
</div>
</div>
Expand Down Expand Up @@ -202,7 +224,7 @@
</div>
</div>

<div class="row">
<div class="row">
<div class="span12 tags" style="margin-bottom: 3px;">
<% job.tags.each do |tag| %>
<div class="btn-group" style="float:left">
Expand Down Expand Up @@ -231,7 +253,7 @@
</div>
</div>
<% end %>
<hr/>
<hr/>
</div>
</div>
<% end %>
2 changes: 1 addition & 1 deletion lib/qless/server/views/throttles.erb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
</div>
<% else %>
<div class="page-header">
<h1>Throttles <small>By queue.</small></h1>
<h1>Throttles <small>for queue concurrency</small></h1>
</div>

<table class="table">
Expand Down
72 changes: 66 additions & 6 deletions spec/integration/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)
test_pagination
end

it 'can set and delete throttles for all the queues', js: true do
it 'can set and delete queues throttles', js: true do
q.put(Qless::Job, {})

text_field_class = ".#{q.name}-maximum"
Expand All @@ -138,7 +138,7 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)

maximum = first(text_field_class)
maximum.set(3)
maximum.trigger('blur');
maximum.trigger('blur')

first(text_field_class, value: /3/i).should be
throttle.maximum.should eq(3)
Expand All @@ -149,7 +149,7 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)
first(text_field_class, value: /0/i).should be
end

it 'can set the expiration for throttles', js: true do
it 'can set the expiration for queue throttles', js: true do
q.put(Qless::Job, {})

maximum_field_class = ".#{q.name}-maximum"
Expand All @@ -166,20 +166,80 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)

maximum = first(maximum_field_class)
maximum.set(3)
maximum.trigger('blur');
maximum.trigger('blur')

first(maximum_field_class, value: /3/i).should be
throttle.maximum.should eq(3)

expiration = first(expiration_field_class)
expiration.set(1)
expiration.trigger('blur');
expiration.trigger('blur')

visit '/throttles'

first(maximum_field_class, value: /0/i).should be
first(expiration_field_class, placeholder: /-2/i).should be
end

it 'can set and delete job throttles', js: true do
t_id = 'wakka' # the throttle id
jid = q.put(Qless::Job, {}, throttles: [t_id])

text_field_class = ".#{t_id}-maximum"
throttle = Throttle.new(t_id, client)

throttle.maximum.should eq(0)

visit "/jobs/#{jid}"

page.should have_content(t_id)
first(".#{t_id}-maximum", placeholder: /0/i).should be

maximum = first(".#{t_id}-maximum")
maximum.set(3)
maximum.trigger('blur')

first(".#{t_id}-maximum", value: /3/i).should be
throttle.maximum.should eq(3)

first('button.btn-danger.remove-throttle').click
first('button.btn-danger.remove-throttle').click

first(".#{t_id}-maximum", value: /0/i).should be
end

it 'can set the expiration for job throttles', js: true do
t_id = 'wakka' # the throttle id
jid = q.put(Qless::Job, {}, throttles: [t_id])

maximum_field_class = ".#{t_id}-maximum"
expiration_field_class = ".#{t_id}-expiration"
throttle = Throttle.new(t_id, client)

throttle.maximum.should eq(0)
throttle.ttl.should eq(-2)

visit "/jobs/#{jid}"

page.should have_content(t_id)
first(".#{t_id}-expiration", placeholder: /-2/i).should be

maximum = first(".#{t_id}-maximum")
maximum.set(3)
maximum.trigger('blur')

first(".#{t_id}-maximum", value: /3/i).should be
throttle.maximum.should eq(3)

expiration = first(".#{t_id}-expiration")
expiration.set(1)
expiration.trigger('blur')

visit "/jobs/#{jid}"

first(".#{t_id}-maximum", value: /0/i).should be
first(".#{t_id}-expiration", placeholder: /-2/i).should be
end

it 'can see the root-level summary' do
visit '/'
Expand Down Expand Up @@ -329,7 +389,7 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)
job.move('testing')
q.pop.complete
visit "/jobs/#{job.jid}"
first('i.icon-remove').should be_nil
first('i.icon-remove.cancel-job').should be_nil
first('i.icon-repeat').should be_nil
first('i.icon-flag').should be
first('i.caret').should be
Expand Down