8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/unique_job/util.rb', line 8
def perform(worker, job, &block)
if worker.respond_to?(:unique_key)
key = worker.unique_key(*job['args'])
logger.debug { "[UniqueJob] Unique key calculated context=#{@context} worker=#{job['class']} key=#{key}" }
if key.nil? || key.to_s.empty?
logger.warn { "[UniqueJob] Skip history check context=#{@context} worker=#{job['class']} key=#{key}" }
yield
else
if @history.exists?(job['class'], key)
logger.info { "[UniqueJob] Duplicate job skipped context=#{@context} worker=#{job['class']} key=#{key}" }
perform_callback(worker, :after_skip, job['args'])
nil
else
logger.debug { "[UniqueJob] Start job context=#{@context} worker=#{job['class']} key=#{key}" }
ttl = worker.respond_to?(:unique_in) ? worker.unique_in : 3600
@history.add(job['class'], key, ttl)
yield
end
end
else
yield
end
end
|