Skip to content
This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
mrflip edited this page Sep 12, 2010 · 11 revisions

Check out

  • the README for most recent info.
  • http://robey.lag.net/2008/11/27/scarling-to-kestrel.html
  • The Starling repo — Kestrel’s interface is similar to but more powerful than Starling’s.
  • [Blocking Fetch]
  • [Reliable Fetch]
    -————————————————————

Basic usage

  class Broker
    require 'memcached'
    QUEUE_SLEEP_TIME  = 200
    MEMCACHED_TIMEOUT = 0.250
    def queue
      @queue ||= Memcached.new(['localhost:22133'], :timeout => MEMCACHED_TIMEOUT)
    end

    def process_tasks &block
      loop do
        task = start_task or next
        success = yield task     # does stuff
        warn "Task failed: #{task.inspect}" if (! success)
        complete_task
      end
    end

    # Retrieve a task. Returns nil on error or timeout
    def start_task
      begin
        task = queue.get("#{task}/open/t=#{QUEUE_SLEEP_TIME}") 
      rescue RuntimeError => e; warn e ; return ; end
    end

    def complete_task
       queue.get("#{task}/close") rescue nil
    end

  end
Clone this wiki locally