Class: RightScale::PendingRequests
- Defined in:
- lib/right_agent/pending_requests.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
- 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, pending_request) ⇒ Object
Store pending request.
-
#initialize ⇒ PendingRequests
constructor
Create cache.
-
#kind(kind) ⇒ Object
Select cache entries of the given kind.
-
#oldest_age ⇒ Object
Get age of oldest pending request.
-
#youngest_age ⇒ Object
Get age of youngest pending request.
Constructor Details
#initialize ⇒ PendingRequests
Create cache
65 66 67 68 |
# File 'lib/right_agent/pending_requests.rb', line 65 def initialize @last_cleanup = Time.now super end |
Instance Method Details
#[]=(token, pending_request) ⇒ Object
Store pending request
Parameters
- token(String)
-
Generated message identifier
- pending_request(PendingRequest)
-
Pending request
Return
- (PendingRequest)
-
Stored request
78 79 80 81 82 83 84 85 |
# File 'lib/right_agent/pending_requests.rb', line 78 def []=(token, pending_request) now = Time.now if (now - @last_cleanup) > MIN_CLEANUP_INTERVAL self.reject! { |t, r| r.kind == :send_push && (now - r.receive_time) > MAX_PUSH_AGE } @last_cleanup = now end super end |
#kind(kind) ⇒ Object
Select cache entries of the given kind
Parameters
- kind(Symbol)
-
Kind of request to be included: :send_push or :send_request
Return
- (Hash)
-
Requests of specified kind
94 95 96 |
# File 'lib/right_agent/pending_requests.rb', line 94 def kind(kind) self.reject { |t, r| r.kind != kind} end |
#oldest_age ⇒ Object
Get age of oldest pending request
Return
- age(Integer)
-
Age of oldest request
116 117 118 119 120 121 122 123 124 |
# File 'lib/right_agent/pending_requests.rb', line 116 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
102 103 104 105 106 107 108 109 110 |
# File 'lib/right_agent/pending_requests.rb', line 102 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 |