Class: SyncMachine::EnsurePublication::Deduper

Inherits:
Object
  • Object
show all
Defined in:
lib/sync_machine/ensure_publication/deduper.rb

Overview

Ensures that the current job is not:

  1. Currently being run by another worker

  2. Rendered unnecessary by the fact another job with the same subject was completed since the time this job was requested.

Instance Method Summary collapse

Constructor Details

#initialize(enqueue_time_str:, last_job_finished_at:, job_class:, subject_id:) ⇒ Deduper

Returns a new instance of Deduper.



8
9
10
11
12
13
# File 'lib/sync_machine/ensure_publication/deduper.rb', line 8

def initialize(enqueue_time_str:, last_job_finished_at:, job_class:, subject_id:)
  @enqueue_time_str = enqueue_time_str
  @job_class = job_class
  @last_job_finished_at = last_job_finished_at
  @subject_id = subject_id
end

Instance Method Details

#dedupeObject



15
16
17
18
19
20
21
# File 'lib/sync_machine/ensure_publication/deduper.rb', line 15

def dedupe
  lock = RedisLock.new("#{@job_class.name}:#{@subject_id}")
  lock.acquire do
    yield unless performed_since_enqueue_time?
  end
  lock.acquired? || reschedule_job
end