Sha256: ec3bec0a482a8a461d0ea00dfbda8c00d299e9049d8691aed8b0eb58bb48dbbd

Contents?: true

Size: 952 Bytes

Versions: 2

Compression:

Stored size: 952 Bytes

Contents

module Lux::DelayedJob
  extend self

  @@server = nil

  def server= name
    adapter = "Lux::DelayedJob::#{name.to_s.capitalize}"
    @@server = adapter.constantize
  rescue NameError
    die 'No adapter %s not found' % adapter
  end

  def push object, method_to_call=nil
    die "No DelayedJob server defined" unless @@server
    @@server.push [object, method_to_call]
  end

  def pop
    obj, method_to_call = @@server.pop
    return unless obj
    puts "JOB POP> #{obj.to_s}.#{method_to_call}".yellow
    if method_to_call
      begin
        obj.send(method_to_call)
      rescue
        puts("Lux::DelayedJob.pop FAIL for :#{method_to_call} (#{$!.message})".red)
      end
    else
      eval(obj)
    end
    true
  end

  def run! seconds=2
    puts "JOB QUE> is running for #{@@server}".green
    Thread.new do
      while true
        print '.'
        true while Lux::DelayedJob.pop
        sleep seconds
      end
    end.join
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
lux-fw-0.2.3 ./lib/lux/delayed_job/delayed_job.rb
lux-fw-0.2.1 ./lib/lux/delayed_job/delayed_job.rb