Class: Jiggler::Retrier

Inherits:
Object
  • Object
show all
Includes:
Support::Helper
Defined in:
lib/jiggler/retrier.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Support::Helper

#log_error, #log_error_short, #logger, #safe_async, #scan_all, #tid

Constructor Details

#initialize(config, collection) ⇒ Retrier

Returns a new instance of Retrier.



9
10
11
12
13
# File 'lib/jiggler/retrier.rb', line 9

def initialize(config, collection)
  @config = config
  @collection = collection
  @tid = tid
end

Instance Attribute Details

#collectionObject (readonly)

Returns the value of attribute collection.



7
8
9
# File 'lib/jiggler/retrier.rb', line 7

def collection
  @collection
end

#configObject (readonly)

Returns the value of attribute config.



7
8
9
# File 'lib/jiggler/retrier.rb', line 7

def config
  @config
end

Instance Method Details

#wrapped(instance, parsed_job, queue) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/jiggler/retrier.rb', line 15

def wrapped(instance, parsed_job, queue)
  logger.info {
    "Starting #{instance.class.name} queue=#{instance.class.queue} tid=#{@tid} jid=#{parsed_job['jid']}"
  }
  yield
  logger.info { 
    "Finished #{instance.class.name} queue=#{instance.class.queue} tid=#{@tid} jid=#{parsed_job['jid']}"
  }
rescue Async::Stop => stop
  raise stop
rescue => err
  raise Async::Stop if exception_caused_by_shutdown?(err)

  process_retry(instance, parsed_job, queue, err)
  collection.incr_failures
  
  log_error(
    err,
    context: '\'Job raised exception\'',
    error_class: err.class.name,
    name: parsed_job['name'],
    queue: parsed_job['queue'],
    args: parsed_job['args'],
    attempt: parsed_job['attempt'],
    tid: @tid,
    jid: parsed_job['jid']
  )
end