Module: Que::Locks::JobExtensions
- Defined in:
- lib/que/locks/job_extensions.rb
Instance Attribute Summary collapse
-
#exclusive_execution_lock ⇒ Object
Returns the value of attribute exclusive_execution_lock.
Instance Method Summary collapse
- #enqueue(*args, queue: nil, priority: nil, run_at: nil, job_class: nil, tags: nil, job_options: {}, **kwargs) ⇒ Object
-
#lock_available?(*args, queue: nil, priority: nil, run_at: nil, job_class: nil, tags: nil, job_options: {}, **kwargs) ⇒ Boolean
rubocop:disable Lint/UnusedMethodArgument.
Instance Attribute Details
#exclusive_execution_lock ⇒ Object
Returns the value of attribute exclusive_execution_lock.
3 4 5 |
# File 'lib/que/locks/job_extensions.rb', line 3 def exclusive_execution_lock @exclusive_execution_lock end |
Instance Method Details
#enqueue(*args, queue: nil, priority: nil, run_at: nil, job_class: nil, tags: nil, job_options: {}, **kwargs) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/que/locks/job_extensions.rb', line 12 def enqueue(*args, queue: nil, priority: nil, run_at: nil, job_class: nil, tags: nil, job_options: {}, **kwargs) forwardable_kwargs = kwargs.clone forwardable_kwargs[:job_options] = { queue: queue, priority: priority, run_at: run_at, job_class: job_class, tags: , }.merge() if self.exclusive_execution_lock args_list = args.clone args_list << kwargs if kwargs.any? if Que::Locks::ExecutionLock.already_enqueued_job_wanting_lock?(self, args_list) Que.log(level: :info, event: :skipped_enqueue_due_to_preemptive_lock_check, args: args_list) # This technically breaks API compatibility with que, which always # returns a job. It could be argued that we should return the # already-enqueued job, but then we'd lose the ability to signal to # the caller that a job wasn't actually enqueued. Let's see how # far we can get with this. return end end super(*args, **forwardable_kwargs) end |
#lock_available?(*args, queue: nil, priority: nil, run_at: nil, job_class: nil, tags: nil, job_options: {}, **kwargs) ⇒ Boolean
rubocop:disable Lint/UnusedMethodArgument
5 6 7 8 9 10 |
# File 'lib/que/locks/job_extensions.rb', line 5 def lock_available?(*args, queue: nil, priority: nil, run_at: nil, job_class: nil, tags: nil, job_options: {}, **kwargs) # rubocop:disable Lint/UnusedMethodArgument args << kwargs if kwargs.any? return true unless self.exclusive_execution_lock return false if Que::Locks::ExecutionLock.already_enqueued_job_wanting_lock?(self, args) return Que::Locks::ExecutionLock.can_acquire?(self, args) end |