Module: ActiveJobLock::Core
- Defined in:
- lib/active_job_lock/core.rb
Overview
If you want only one instance of your job running at a time, include this module:
class UpdateNetworkGraph < ActiveJob::Base
include ActiveJobLock::Core
queue_as :network_graph
def perform(repo_id)
heavy_lifting
end
end
If you wish to limit the duration a lock may be held for, you can set/override ‘lock_timeout`. e.g.
class UpdateNetworkGraph < ActiveJob::Base
include ActiveJobLock::Core
queue_as :network_graph
# lock may be held for upto an hour.
lock timeout: 3600
def perform(repo_id)
heavy_lifting
end
end
If you wish that only one instance of the job defined by #identifier may be enqueued or running, you can set/override ‘loner`. e.g.
class PdfExport < ActiveJob::Base
include ActiveJobLock::Core
queue_as :exports
# only one job can be running/enqueued at a time. For instance a button
# to run a PDF export. If the user clicks several times on it, enqueue
# the job if and only if
# - the same export is not currently running
# - the same export is not currently queued.
# ('same' being defined by `identifier`)
lock loner: true
def perform(repo_id)
heavy_lifting
end
end
Defined Under Namespace
Modules: ClassMethods, OverriddenMethods
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.included(base) ⇒ Object
49 50 51 |
# File 'lib/active_job_lock/core.rb', line 49 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#initialize(*args) ⇒ Object
62 63 64 65 |
# File 'lib/active_job_lock/core.rb', line 62 def initialize(*args) super(*args) self.extend(OverriddenMethods) end |