Sha256: 99096f524bc2f949ab88b368a4be002163c7ed9c0e8891745912c3efe71e4981
Contents?: true
Size: 856 Bytes
Versions: 11
Compression:
Stored size: 856 Bytes
Contents
require 'active_support/concern' module RocketJob module Plugins # Prevent this job from being saved if another is running, queued, or paused. module Singleton extend ActiveSupport::Concern included do validate :rocket_job_singleton_check end # Returns [true|false] whether another instance of this job is already active def rocket_job_singleton_active? self.class.where(:state.in => %i[running queued], :id.ne => id).exists? end private # Validation prevents a new job from being saved while one is already running def rocket_job_singleton_check return unless (running? || queued? || paused?) && rocket_job_singleton_active? errors.add(:state, "Another instance of #{self.class.name} is already running, queued, or paused") end end end end
Version data entries
11 entries across 11 versions & 1 rubygems