Permalink
Browse files

Added some simple rake tests for loading to and pulling from test queues

  • Loading branch information...
1 parent 1ed995d commit 8e726f2a280538b5a8cc4be1f5428b3079b53e81 @denniskuczynski committed Aug 6, 2012
Showing with 48 additions and 4 deletions.
  1. +41 −0 Rakefile
  2. +4 −4 lib/beanstalkd_view/server.rb
  3. +3 −0 lib/beanstalkd_view/views/peek_range.erb
View
41 Rakefile
@@ -10,3 +10,44 @@ RSpec::Core::RakeTask.new(:spec)
task :default => :spec
+require 'beanstalk-client'
+require 'json'
+
+namespace :beanstalkd_view do
+
+ TEST_QUEUES = ['tube_sock', 'test_tube', 'tube_top', 'inner_tube']
+
+ # Randomly enqueue elements to test queues
+ task :enqueue_test do
+ host = "localhost"
+ port = 11300
+ beanstalk = Beanstalk::Pool.new([ "#{host}:#{port}" ])
+
+ # Loop flooding the queues with jobs
+ while true
+ tube = TEST_QUEUES.sample
+ pri = 65536
+ delay = 0
+ ttr = 120
+ beanstalk.use tube
+ beanstalk.put [ tube, {} ].to_json, pri, delay, ttr
+ puts "Enqueued Job to #{tube}"
+ end
+ end
+
+ # Randomly pull elements from test queues
+ task :pull_test do
+ host = "localhost"
+ port = 11300
+ beanstalk = Beanstalk::Pool.new([ "#{host}:#{port}" ])
+
+ while true
+ tube = TEST_QUEUES.sample
+ beanstalk.watch(tube)
+ job = beanstalk.reserve
+ puts "Pulled Job #{job} from #{tube}"
+ job.delete
+ end
+ end
+
+end
View
8 lib/beanstalkd_view/server.rb
@@ -117,11 +117,11 @@ class Server < Sinatra::Base
guess_tubes << @tube
end
# Guess ID Range if not specified
- @min = guess_min_peek_range(guess_tubes) if @min == 0
- @max = guess_max_peek_range(@min) if @max == 0
+ min = guess_min_peek_range(guess_tubes) if @min == 0
+ max = guess_max_peek_range(min) if @max == 0
@jobs = []
- for i in @min..@max
+ for i in min..max
begin
response = beanstalk.peek_job(i)
if response
@@ -132,7 +132,7 @@ class Server < Sinatra::Base
@jobs << ret_value
end
rescue Exception => e
- puts e
+ #puts "Ignoring NotFoundError: #{ex.class}: #{ex}"
end
end
erb :peek_range
View
3 lib/beanstalkd_view/views/peek_range.erb
@@ -1,6 +1,9 @@
<div class="row">
<div class="span12">
<h3>Peek Range</h3>
+ <div class="alert alert-success">
+ <strong>NOTE:</strong> Setting min and max to 0 will attempt to guess an appropriate range value based on the current ready queue.
+ </div>
<form class="well form-inline" name="peek_range_form" action="<%= u("/peek-range") %>" method="GET">
<input type="text" class="span2" name="min" value="<%= @min %>">
<input type="text" class="span2" name="max" value="<%= @max %>">

0 comments on commit 8e726f2

Please sign in to comment.