Sha256: 1fa99567e882392758aa1aefbc7a9c6ff407bf0e32fc79c59279c3d2f6fc30a3

Contents?: true

Size: 1.48 KB

Versions: 2

Compression:

Stored size: 1.48 KB

Contents

require 'drydock'

module Bluth
  class CLI < Drydock::Command
    
    
    def start_workers
      start_worker
    end
    
    def start_scheduler
      start_worker Bluth.scheduler
    end
    
    def stop_scheduler
      stop_workers Bluth.scheduler
    end
    
    def schedulers
      workers Bluth.scheduler
    end
    
    #def flush_workers
    #  if @global.auto || Annoy.are_you_sure?
    #    Bluth::Worker.prefix
    #  end
    #end
    
    def start_worker worker_class=Bluth::Worker
      if @global.daemon
        worker = worker_class.new
        Familia.info "Created: #{worker.rediskey}"
        worker.daemonize
        worker.run
      else
        Bluth.poptimeout = 3.seconds
        worker_class.run
      end
    end
    
    def stop_workers worker_class=Bluth::Worker
      worker_class.instances.each do |worker|
        kill_worker worker, worker_class
      end
    end
    
    def stop_worker wid=nil,worker_class=Bluth::Worker
      wids = wid ? [wid] : @argv
      wids.each do |wid|
        worker = worker_class.from_redis wid
        kill_worker worker, worker_class
      end
    end
    
    def workers worker_class=Bluth::Worker
      Familia.info worker_class.all.collect &:key
    end
    
    private 
    
    def kill_worker worker, worker_class=Bluth::Worker
      if worker.nil?
        Familia.info "No such worker"
        exit 1
      else
        Familia.info "Killing #{worker.rediskey}"
        worker.kill @global.auto
      end
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
bluth-0.6.1 lib/bluth/cli.rb
bluth-0.6.0 lib/bluth/cli.rb