Sha256: c3fa8b3f421642ed459024a858450d241572534e855b80567f86a0379dce57a9

Contents?: true

Size: 1.51 KB

Versions: 10

Compression:

Stored size: 1.51 KB

Contents

module Taskinator
  module Queues

    # https://github.com/resque/resque

    def self.create_resque_adapter(config={})
      ResqueAdapter.new(config)
    end

    class ResqueAdapter
      def initialize(config={})
        config = {
          :process_queue => :default,
          :task_queue => :default,
          :job_queue => :default
        }.merge(config)

        ProcessWorker.class_eval do
          @queue = config[:process_queue]
        end

        TaskWorker.class_eval do
          @queue = config[:task_queue]
        end

        JobWorker.class_eval do
          @queue = config[:job_queue]
        end
      end

      def enqueue_process(process)
        Resque.enqueue(ProcessWorker, process.uuid)
      end

      def enqueue_task(task)
        Resque.enqueue(TaskWorker, task.uuid)
      end

      def enqueue_job(job)
        # get the queue name
        queue = Resque.queue_from_class(job.job) ||
                  Resque.queue_from_class(JobWorker)

        Resque.enqueue_to(queue, JobWorker, job.uuid)
      end

      class ProcessWorker
        def self.perform(process_uuid)
          Taskinator::ProcessWorker.new(process_uuid).perform
        end
      end

      class TaskWorker
        def self.perform(task_uuid)
          Taskinator::TaskWorker.new(task_uuid).perform
        end
      end

      class JobWorker
        def self.perform(job_uuid)
          Taskinator::JobWorker.new(job_uuid).perform do |job, args|
            job.perform(*args)
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
taskinator-0.0.14 lib/taskinator/queues/resque.rb
taskinator-0.0.13 lib/taskinator/queues/resque.rb
taskinator-0.0.12 lib/taskinator/queues/resque.rb
taskinator-0.0.11 lib/taskinator/queues/resque.rb
taskinator-0.0.10 lib/taskinator/queues/resque.rb
taskinator-0.0.9 lib/taskinator/queues/resque.rb
taskinator-0.0.8 lib/taskinator/queues/resque.rb
taskinator-0.0.7 lib/taskinator/queues/resque.rb
taskinator-0.0.5 lib/taskinator/queues/resque.rb
taskinator-0.0.4 lib/taskinator/queues/resque.rb