Sha256: d728faa49e80793ca26154ee90d166659814d2cb80e9fd13949e1582a973abdf

Contents?: true

Size: 848 Bytes

Versions: 8

Compression:

Stored size: 848 Bytes

Contents

require 'socket'

module BatchManager
  class ApplicationController < ActionController::Base
    helper_method :resque_supported?, :local_resque_worker?, :resque_worker_hostname

    def resque_supported?
      begin
        require 'resque'
        defined?(Resque) && resque_worker
      rescue LoadError
        false
      end
    end

    def local_resque_worker?
      Socket.gethostname == resque_worker_hostname
    end

    def resque_worker_hostname
      resque_worker.id.split(':')[0]
    end

    private

    def resque_worker
      @resque_worker ||= begin
        workers = Resque.workers.select do |worker|
          queue_names = worker.id.split(':')[-1].split(',')
          queue_names.include?(BatchManager::ExecBatchWorker.queue_name) || queue_names.include?("*")
        end
        workers.first
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
batch_manager-0.4.1 app/controllers/batch_manager/application_controller.rb
batch_manager-0.4.0 app/controllers/batch_manager/application_controller.rb
batch_manager-0.3.9 app/controllers/batch_manager/application_controller.rb
batch_manager-0.3.8 app/controllers/batch_manager/application_controller.rb
batch_manager-0.3.7 app/controllers/batch_manager/application_controller.rb
batch_manager-0.3.6 app/controllers/batch_manager/application_controller.rb
batch_manager-0.3.5 app/controllers/batch_manager/application_controller.rb
batch_manager-0.3.4 app/controllers/batch_manager/application_controller.rb