summaryrefslogtreecommitdiff
path: root/queue/zset/run_with_threads.rb
diff options
context:
space:
mode:
authorSteve Kemp <steve@steve.org.uk>2016-01-18 14:16:07 +0200
committerSteve Kemp <steve@steve.org.uk>2016-01-18 14:16:07 +0200
commitc6f2c6f924e6b263be5a3ba4a4eb7049f27544d3 (patch)
treee023f6bbef8a2ecf8829a0d0ab5214b902266bc7 /queue/zset/run_with_threads.rb
parentfbd4e3bf99afbc80012d6dc029be19e1bd8e6890 (diff)
Removed queue-examples.
These are no longer required now we're sure we understand the process of adding jobs to the queue without duplication.
Diffstat (limited to 'queue/zset/run_with_threads.rb')
-rw-r--r--queue/zset/run_with_threads.rb75
1 files changed, 0 insertions, 75 deletions
diff --git a/queue/zset/run_with_threads.rb b/queue/zset/run_with_threads.rb
deleted file mode 100644
index cba3eda..0000000
--- a/queue/zset/run_with_threads.rb
+++ /dev/null
@@ -1,75 +0,0 @@
-
-#!/usr/bin/ruby
-
-require "redis"
-require 'pp'
-
-class Arse
-
- def initialize(name)
- @name = name
- @redis = Redis.new(:host => "127.0.0.1")
- end
-
- def fetch(timeout = 1)
- loop do
- job = nil
- @redis.watch("zset")
-
- job = @redis.zrange('zset', '0', '0')
-
- if job.is_a?(Array) and !job.empty?
- # We only have one entry in our array
- job = job[0]
-
- res = @redis.multi do
- # Remove from the queue
- @redis.zrem('zset', job );
- end
- job = nil if res.nil?
- end
-
- @redis.unwatch
-
- return job if job.is_a?(String)
-
- sleep(timeout)
- end
- end
-
- def run
- Thread.new do
- while( x = fetch() )
- print "\n" if x == "test 1"
- print "#{@name}:#{x}.. "
-
- $count[x] += 1
-
- if ( rand(10) > 5 )
- sleep 1
- end
-
- end
-
- end
- end
-
-end
-
-$count = Hash.new{|h,k| h[k] = 0}
-$threads = []
-
-Signal.trap("INT") do
- pp $count
- exit
-end
-
-$threads = [Arse.new("a").run, Arse.new("b").run, Arse.new("c").run]
-
-while $threads.any?{|t| t.alive?} do
- $threads.each do |t|
- next if t.alive?
- t.join
- end
- sleep 1
-end