Sha256: 00f8dd5ba632bda8d86a5ac759c3c787bf2615579de87443718a5df7b8425830

Contents?: true

Size: 1020 Bytes

Versions: 2

Compression:

Stored size: 1020 Bytes

Contents

module MultiWorker
  module Adapters
    class Que
      def self.configure(base, opts={})
        base.class_eval do
          @queue = opts[:queue]

          def self.perform(*args)
            self.new.perform(*args)
          end

          def self.perform_async(*args)
            @job_klass.queue(*args)
          end

          def perform_async(*args)
            self.class.perform_async(*args)
          end

          worker_klass = self

          @job_klass = Class.new(::Que::Job)
          @job_klass.class_eval do
            @worker_klass = worker_klass

            class << self
              attr_reader :worker_klass
            end

            def run(*args)
              self.class.worker_klass.new.perform(*args)
            end
          end

          const_set :Job, @job_klass
        end
      end

      def self.rake_task
        require 'rake'
        require 'que/rake_tasks'

        ::Rake::Task['que:work']
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
multi_worker-0.2.0 lib/multi_worker/adapters/que.rb
multi_worker-0.1.0 lib/multi_worker/adapters/que.rb