Module: ThreeScale::Backend::ErrorStorage

Extended by:
ErrorStorage
Includes:
StorageHelpers
Included in:
ErrorStorage
Defined in:
lib/3scale/backend/error_storage.rb

Constant Summary collapse

PER_PAGE =
100
MAX_NUM_ERRORS =
1000

Instance Method Summary collapse

Instance Method Details

#count(service_id) ⇒ Object



30
31
32
# File 'lib/3scale/backend/error_storage.rb', line 30

def count(service_id)
  storage.llen(queue_key(service_id))
end

#delete_all(service_id) ⇒ Object



34
35
36
# File 'lib/3scale/backend/error_storage.rb', line 34

def delete_all(service_id)
  storage.del(queue_key(service_id))
end

#list(service_id, options = {}) ⇒ Object

Pages start at 1, same as in will_paginate.



21
22
23
24
25
26
27
28
# File 'lib/3scale/backend/error_storage.rb', line 21

def list(service_id, options = {})
  page     = options[:page] || 1
  per_page = options[:per_page] || PER_PAGE
  range    = pagination_to_range(page.to_i, per_page.to_i)

  raw_items = (storage.lrange(queue_key(service_id), range.begin, range.end) || [])
  raw_items.map(&method(:decode))
end

#store(service_id, error, context_info = {}) ⇒ Object



10
11
12
13
14
15
16
17
18
# File 'lib/3scale/backend/error_storage.rb', line 10

def store(service_id, error, context_info = {})
  request_info = context_info[:request] || {}
  storage.lpush(queue_key(service_id),
                encode(code:         error.code,
                       message:      error.message,
                       timestamp:    Time.now.getutc.to_s,
                       context_info: request_info))
  storage.ltrim(queue_key(service_id), 0, MAX_NUM_ERRORS - 1)
end