Class: RightScale::Sender::PendingRequests
- Defined in:
- lib/right_agent/sender.rb
Overview
Cache for requests that are waiting for a response Automatically deletes push requests when get too old Retains non-push requests until explicitly deleted
Constant Summary collapse
- REQUEST_KINDS =
Kinds of send requests
[:send_retryable_request, :send_persistent_request]
- PUSH_KINDS =
Kinds of send pushes
[:send_push, :send_persistent_push]
- MAX_PUSH_AGE =
Maximum number of seconds to retain send pushes in cache
2 * 60
- MIN_CLEANUP_INTERVAL =
Minimum number of seconds between push cleanups
15
Instance Method Summary collapse
-
#[]=(token, request) ⇒ Object
Store pending request.
-
#initialize ⇒ PendingRequests
constructor
Create cache.
-
#kind(kinds) ⇒ Object
Select cache entries of the given kinds.
-
#oldest_age ⇒ Object
Get age of oldest pending request.
-
#youngest_age ⇒ Object
Get age of youngest pending request.
Constructor Details
#initialize ⇒ PendingRequests
Create cache
73 74 75 76 |
# File 'lib/right_agent/sender.rb', line 73 def initialize @last_cleanup = Time.now super end |
Instance Method Details
#[]=(token, request) ⇒ Object
Store pending request
Parameters
- token(String)
-
Generated message identifier
- request(PendingRequest)
-
Pending request
Return
- (PendingRequest)
-
Stored request
86 87 88 89 90 91 92 93 |
# File 'lib/right_agent/sender.rb', line 86 def []=(token, request) now = Time.now if (now - @last_cleanup) > MIN_CLEANUP_INTERVAL self.reject! { |t, r| PUSH_KINDS.include?(r.kind) && (now - r.receive_time) > MAX_PUSH_AGE } @last_cleanup = now end super end |
#kind(kinds) ⇒ Object
Select cache entries of the given kinds
Parameters
- kinds(Array)
-
Kind of requests to be included
Return
- (Hash)
-
Requests of specified kind
102 103 104 |
# File 'lib/right_agent/sender.rb', line 102 def kind(kinds) self.reject { |t, r| !kinds.include?(r.kind) } end |
#oldest_age ⇒ Object
Get age of oldest pending request
Return
- age(Integer)
-
Age of oldest request
124 125 126 127 128 129 130 131 132 |
# File 'lib/right_agent/sender.rb', line 124 def oldest_age now = Time.now age = nil self.each_value do |r| seconds = (now - r.receive_time).to_i age = seconds if age.nil? || seconds > age end age end |
#youngest_age ⇒ Object
Get age of youngest pending request
Return
- age(Integer)
-
Age of youngest request
110 111 112 113 114 115 116 117 118 |
# File 'lib/right_agent/sender.rb', line 110 def youngest_age now = Time.now age = nil self.each_value do |r| seconds = (now - r.receive_time).to_i age = seconds if age.nil? || seconds < age end age end |