From 43d6c5affc78755f8a45b242d8d39acc72bd3526 Mon Sep 17 00:00:00 2001 From: Steve Kemp Date: Fri, 18 Dec 2015 15:44:24 +0200 Subject: Document queue --- queue/list/add.rb | 22 ++++++++++++++++++++++ queue/list/run.rb | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100755 queue/list/add.rb create mode 100755 queue/list/run.rb diff --git a/queue/list/add.rb b/queue/list/add.rb new file mode 100755 index 0000000..a8676d9 --- /dev/null +++ b/queue/list/add.rb @@ -0,0 +1,22 @@ +#!/usr/bin/ruby +# +# Add the same three tests over and over again. +# +# +require "redis" + +@redis = Redis.new(:host => "127.0.0.1") + + +x = [] + +x.push( "http://example.com/ must run http otherwise 'fail'" ) +x.push( "1.2.3.4 must run ping otherwise 'fail'" ) +x.push( "https://steve.net/ must run https otherwise 'fail'" ) + + +for i in 0 .. 10 + x.each do |test| + @redis.lpush('list', test) + end +end diff --git a/queue/list/run.rb b/queue/list/run.rb new file mode 100755 index 0000000..08623b0 --- /dev/null +++ b/queue/list/run.rb @@ -0,0 +1,32 @@ +#!/usr/bin/ruby + +require "redis" +require 'pp' +@redis = Redis.new(:host => "127.0.0.1") + + + +def fetch(timeout = 1) + job = nil + + loop do + job = @redis.lpop('list') + + if !job.nil? + return job + else + sleep(timeout) + end + + end +end + + + +while( x = fetch() ) + puts "Got job : #{x}" + if ( x =~ /ping/i ) + puts "PING TEST - sleeping" + sleep 5 + end +end -- cgit v1.2.1