summaryrefslogtreecommitdiff
path: root/queue/zset/run.rb
blob: 726e19a5e53b05d6c9d2753574a46171c99e2f85 (plain)
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
#!/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.ZREVRANGE('zset', '0', '0')

    if !job.empty?
      # We only have one entry in our array
      job = job[0]

      # Remove from the queue
      @redis.zrem('zset', job );

      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