module ActiveJobLock::Core::OverriddenMethods
Public Instance Methods
enqueue(*_)
click to toggle source
@abstract if the job is a ‘loner`, enqueue only if no other same job is already running/enqueued
Calls superclass method
# File lib/active_job_lock/core.rb, line 72 def enqueue(*_) if loner if loner_locked?(*arguments) # Same job is currently running loner_enqueue_failed(*arguments) return else acquire_loner_lock!(*arguments) end end super end
perform(*arguments)
click to toggle source
Where the magic happens.
Calls superclass method
# File lib/active_job_lock/core.rb, line 87 def perform(*arguments) lock_until = acquire_lock!(*arguments) # Release loner lock as job has been dequeued release_loner_lock!(*arguments) if loner # Abort if another job holds the lock. return unless lock_until begin super(*arguments) ensure # Release the lock on success and error. Unless a lock_timeout is # used, then we need to be more careful before releasing the lock. now = Time.now.to_i if lock_until != true and lock_until < now # Eeek! Lock expired before perform finished. Trigger callback. lock_expired_before_release(*arguments) else release_lock!(*arguments) end end end