Module: RocketJob::Plugins::Singleton

Extended by:
ActiveSupport::Concern
Defined in:
lib/rocket_job/plugins/singleton.rb

Overview

Prevent this job from being saved if another is running, queued, or paused.

Instance Method Summary collapse

Instance Method Details

#rocket_job_singleton_active?Boolean

Returns [true|false] whether another instance of this job is already active

Returns:

  • (Boolean)


14
15
16
17
18
# File 'lib/rocket_job/plugins/singleton.rb', line 14

def rocket_job_singleton_active?
  self.class.with(read: {mode: :primary}) do |conn|
    conn.where(:state.in => %i[running queued], :id.ne => id).exists?
  end
end