Class: ThreeScale::Backend::EventStorage
- Inherits:
-
Object
- Object
- ThreeScale::Backend::EventStorage
- Extended by:
- StorageHelpers
- Defined in:
- lib/3scale/backend/event_storage.rb
Class Method Summary collapse
- .delete(id) ⇒ Object
- .delete_range(to_id) ⇒ Object
- .list ⇒ Object
- .ping_if_not_empty ⇒ Object
- .size ⇒ Object
- .store(type, object) ⇒ Object
Class Method Details
.delete(id) ⇒ Object
36 37 38 39 |
# File 'lib/3scale/backend/event_storage.rb', line 36 def delete(id) id = id.to_i (id > 0) ? storage.zremrangebyscore(events_queue_key, id, id) : 0 end |
.delete_range(to_id) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/3scale/backend/event_storage.rb', line 27 def delete_range(to_id) to_id = to_id.to_i if to_id > 0 storage.zremrangebyscore(events_queue_key, 0, to_id) else 0 end end |
.list ⇒ Object
22 23 24 25 |
# File 'lib/3scale/backend/event_storage.rb', line 22 def list raw_events = storage.zrevrange(events_queue_key, 0, -1) raw_events.map { |raw_event| decode_event(raw_event) }.reverse end |
.ping_if_not_empty ⇒ Object
45 46 47 48 49 50 |
# File 'lib/3scale/backend/event_storage.rb', line 45 def ping_if_not_empty if events_hook && pending_ping? request_to_events_hook true end end |
.size ⇒ Object
41 42 43 |
# File 'lib/3scale/backend/event_storage.rb', line 41 def size storage.zcard(events_queue_key) end |
.store(type, object) ⇒ Object
15 16 17 18 19 20 |
# File 'lib/3scale/backend/event_storage.rb', line 15 def store(type, object) fail InvalidEventType, type unless EVENT_TYPES.member?(type) new_id = storage.incrby(events_id_key, 1) event = { id: new_id, type: type, timestamp: Time.now.utc, object: object } storage.zadd(events_queue_key, event[:id], encode(event)) end |