forked from denniskuczynski/beanstalkd_view
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Rakefile
57 lines (46 loc) · 1.3 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
APP_FILE = 'lib/beanstalkd_view.rb'
APP_CLASS = 'BeanstalkdView::Server'
require "bundler/gem_tasks"
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
task :default => :spec
require 'beaneater'
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 = Beaneater.new("#{host}:#{port}")
# Loop flooding the queues with jobs
while true
tube_name = TEST_QUEUES.sample
pri = 65536
delay = 0
ttr = 120
tube = beanstalk.tubes[tube_name]
tube.put '{}', :pri => pri, :delay => delay, :ttr => ttr
puts "Enqueued Job to #{tube_name}"
end
end
# Randomly pull elements from test queues
task :pull_test do
host = "localhost"
port = 11300
beanstalk = Beaneater.new("#{host}:#{port}")
while true
tube_name = TEST_QUEUES.sample
begin
beanstalk.tubes.watch!(tube_name)
job = beanstalk.tubes.reserve(1)
if job
puts "Pulled Job #{job} from #{tube_name}"
job.delete
end
rescue Exception => ex
puts "Exception while pulling job from #{tube_name}: #{ex}"
end
end
end
end