diff --git a/code/main.rb b/code/main.rb index 1f5d97c..a318052 100644 --- a/code/main.rb +++ b/code/main.rb @@ -159,6 +159,19 @@ def flash_now(type, msg) erb :proc_list, :layout => false, :locals => {:queues => RQ::QueueMgrClient.queues, :procs => procs} end + post '/q/:name' do + begin + qc = RQ::QueueClient.new(params[:name]) + rescue RQ::RqQueueNotFound + throw :halt, [404, "404 - Queue not found"] + end + + ok, num_msgs = qc.delete_message({:all => params[:state]}) + + flash :notice, "Deleted #{num_msgs} messages in #{params[:state]} state" + redirect request.path_info + end + get '/q/:name' do if params[:name].index(".txt") content_type 'text/plain', :charset => 'utf-8' diff --git a/code/public/css/rq.css b/code/public/css/rq.css index 58be57c..dfd2475 100644 --- a/code/public/css/rq.css +++ b/code/public/css/rq.css @@ -206,3 +206,9 @@ th.err {background: #f99} } .hidden {display: none} p {margin-bottom: 5px} + +.float-right { + float: right; + padding: 0px; + margin: 0px; +} diff --git a/code/queue.rb b/code/queue.rb index 5960371..294a81b 100644 --- a/code/queue.rb +++ b/code/queue.rb @@ -1928,13 +1928,30 @@ def handle_request(sock) json = packet.split(' ', 2)[1] options = JSON.parse(json) + if options.has_key?('all') + state = options['all'] + unless %w{prep que done err relay}.include? state + resp = [ "fail", "invalid state to delete all messages" ].to_json + send_packet(sock, resp) + return + end + + all_msgs = Dir.glob("#{@queue_path}/#{state}/*") + all_msgs.each do |dir| + FileUtils.rm_rf(dir) + end + resp = [ "ok", all_msgs.length ].to_json + send_packet(sock, resp) + return + end + if not options.has_key?('msg_id') - resp = [ "fail", "lacking 'msg_id' field"].to_json + resp = [ "fail", "lacking 'msg_id' field" ].to_json send_packet(sock, resp) return end - resp = [ "fail", "unknown reason"].to_json + resp = [ "fail", "unknown reason" ].to_json if lookup_msg(options, '*') delete_msg!(options) diff --git a/code/views/queue.erb b/code/views/queue.erb index 8e37238..3c2b747 100644 --- a/code/views/queue.erb +++ b/code/views/queue.erb @@ -33,7 +33,14 @@ <% if qc.name != 'relay' %>