Sha256: 99321aba9c73150a89a91390a340f531546184de279af2cef13b9be5851669b5

Contents?: true

Size: 989 Bytes

Versions: 7

Compression:

Stored size: 989 Bytes

Contents

# encoding: UTF-8
require 'active_support/concern'

# Worker behavior for a job
module RocketJob
  module Concerns
    module Singleton
      extend ActiveSupport::Concern

      included do
        # Start the single instance of this job
        #
        # Returns true if the job was started
        # Returns false if the job is already running and doe not need to be started
        def self.start(*args, &block)
          # Prevent multiple Jobs of the same class from running at the same time
          return false if where(state: [:running, :queued]).count > 0

          perform_later(*args, &block)
          true
        end

        # TODO Make :perform_later, :perform_now, :perform, :now protected/private
        #      class << self
        #        # Ensure that only one instance of the job is running.
        #        protected :perform_later, :perform_now, :perform, :now
        #      end
        #self.send(:protected, :perform_later)

      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rocketjob-1.3.0 lib/rocket_job/concerns/singleton.rb
rocketjob-1.2.1 lib/rocket_job/concerns/singleton.rb
rocketjob-1.2.0 lib/rocket_job/concerns/singleton.rb
rocketjob-1.1.3 lib/rocket_job/concerns/singleton.rb
rocketjob-1.1.2 lib/rocket_job/concerns/singleton.rb
rocketjob-1.1.1 lib/rocket_job/concerns/singleton.rb
rocketjob-1.1.0 lib/rocket_job/concerns/singleton.rb