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
Prev Previous commit
Next Next commit
update throttle endpoints
  • Loading branch information
Gregory Salmon committed Apr 25, 2014
commit 7037cdb79f9d80db0b3bf199bf585036fd1dfd65
46 changes: 23 additions & 23 deletions lib/qless/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,29 @@ def strftime(t)
}
end

post '/throttle' do
# Expects a JSON object: {'id': id, 'maximum': maximum}
data = JSON.parse(request.body.read)
if data['id'].nil? || data['maximum'].nil?
halt 400, 'Need throttle id and maximum value'
else
throttle = Throttle.new(data['id'], client)
throttle.maximum = data['maximum']
end
end

delete '/throttle' do
# Expects a JSON object: {'id': id}
data = JSON.parse(request.body.read)
if data['id'].nil?
halt 400, 'Need throttle id'
else
throttle = Throttle.new(data['id'], client)
throttle.delete
return json({id: throttle.id, maximum: throttle.maximum})
end
end

get '/failed.json' do
json(client.jobs.failed)
end
Expand Down Expand Up @@ -492,29 +515,6 @@ def strftime(t)
end
end

post '/delete_throttle' do
# Expects a JSON object: {'id': id}
data = JSON.parse(request.body.read)
if data['id'].nil?
halt 400, 'Need throttle id'
else
throttle = Throttle.new(data['id'], client)
throttle.delete
return json({id: throttle.id, maximum: throttle.maximum})
end
end

post '/update_throttle' do
# Expects a JSON object: {'id': id, 'maximum': maximum}
data = JSON.parse(request.body.read)
if data['id'].nil? || data['maximum'].nil?
halt 400, 'Need throttle id and maximum value'
else
throttle = Throttle.new(data['id'], client)
throttle.maximum = data['maximum']
end
end

# start the server if ruby file executed directly
run! if app_file == $PROGRAM_NAME
end
Expand Down
19 changes: 12 additions & 7 deletions lib/qless/server/views/layout.erb
Original file line number Diff line number Diff line change
Expand Up @@ -332,22 +332,27 @@
}

var delete_throttle = function(throttle_id) {
_ajax({
url: '<%= u "/delete_throttle" %>',
data: {
'id': throttle_id
}, success: function(data) {
var data = { 'id': throttle_id };

$.ajax({
url: '<%= u "/throttle" %>',
type: 'DELETE',
dataType: 'json',
processData: false,
data: JSON.stringify(data),
success: function(data) {
flash('Deleted throttle for ' + throttle_id, 'success');
$('.throttle-' + throttle_id).val(data['maximum']);
}, error: function(data) {
},
error: function(data) {
flash('Couldn\'t delete thottle ' + throttle_id);
}
})
}

var update_throttle = function(throttle_id, maximum) {
_ajax({
url: '<%= u "/update_throttle" %>',
url: '<%= u "/throttle" %>',
data: {
'id': throttle_id,
'maximum': maximum
Expand Down
5 changes: 2 additions & 3 deletions spec/integration/server_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,12 @@ def test_pagination(page_1_jid = 1, page_2_jid = 27)
maximum.trigger('blur');

first(text_field_class, value: /3/i).should be

throttle.maximum.should eq(3)

first('button.btn-danger').click
first('button.btn-danger').click
throttle.maximum.should eq(0)

first(text_field_class, value: /0/i).should be
end

it 'can see the root-level summary' do
Expand Down