Class: QuickbooksWebConnector::Failure

Inherits:
Object
  • Object
show all
Defined in:
lib/quickbooks_web_connector/failure.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception, payload) ⇒ Failure

Returns a new instance of Failure.



44
45
46
47
# File 'lib/quickbooks_web_connector/failure.rb', line 44

def initialize(exception, payload)
  @exception = exception
  @payload = payload
end

Instance Attribute Details

#exceptionObject

The exception object raised by the failed job



5
6
7
# File 'lib/quickbooks_web_connector/failure.rb', line 5

def exception
  @exception
end

#payloadObject

The payload object associated with the failed job



8
9
10
# File 'lib/quickbooks_web_connector/failure.rb', line 8

def payload
  @payload
end

Class Method Details

.all(start = 0, stop = -1)) ⇒ Object



23
24
25
# File 'lib/quickbooks_web_connector/failure.rb', line 23

def self.all(start = 0, stop = -1)
  QuickbooksWebConnector.list_range(:failed, start, stop)
end

.countObject



19
20
21
# File 'lib/quickbooks_web_connector/failure.rb', line 19

def self.count
  QuickbooksWebConnector.redis.llen(:failed).to_i
end

.create(options = {}) ⇒ Object

Creates a new failure.

Expects a hash with the following keys:

:exception - The Exception object
:payload   - The job's payload


15
16
17
# File 'lib/quickbooks_web_connector/failure.rb', line 15

def self.create(options = {})
  new(*options.values_at(:exception, :payload)).save
end

.find(index) ⇒ Object



27
28
29
# File 'lib/quickbooks_web_connector/failure.rb', line 27

def self.find(index)
  QuickbooksWebConnector.list_range(:failed, index, index).first
end

.remove(index) ⇒ Object



38
39
40
41
42
# File 'lib/quickbooks_web_connector/failure.rb', line 38

def self.remove(index)
  id = rand(0xffffff)
  QuickbooksWebConnector.redis.lset(:failed, index, id)
  QuickbooksWebConnector.redis.lrem(:failed, 1, id)
end

.requeue(index) ⇒ Object



31
32
33
34
35
36
# File 'lib/quickbooks_web_connector/failure.rb', line 31

def self.requeue(index)
  item = find(index)
  item['retried_at'] = Time.now.rfc2822
  QuickbooksWebConnector.redis.lset(:failed, index, QuickbooksWebConnector.encode(item))
  Job.create(item['payload']['request_builder_class'], item['payload']['response_handler_class'], *item['payload']['args'])
end

Instance Method Details

#saveObject



49
50
51
52
53
54
55
56
57
58
59
# File 'lib/quickbooks_web_connector/failure.rb', line 49

def save
  data = {
    failed_at: Time.now.rfc2822,
    payload: payload,
    exception: exception.class.to_s,
    error: exception.to_s,
    backtrace: filter_backtrace(Array(exception.backtrace)),
  }
  data = QuickbooksWebConnector.encode(data)
  QuickbooksWebConnector.redis.rpush(:failed, data)
end