mirror of
https://github.com/Fishwaldo/huginn.git
synced 2025-03-16 03:41:41 +00:00
use strings in hash keys, cleanup old memory
This commit is contained in:
parent
77c623b28e
commit
8d2521208b
1 changed files with 12 additions and 4 deletions
|
@ -76,7 +76,7 @@ module Agents
|
|||
vals = vals.merge Hash.from_xml(pr.to_xml)
|
||||
if not_already_in_memory?(vals)
|
||||
create_event(:payload => vals)
|
||||
add_to_memory(vals)
|
||||
update_memory(vals)
|
||||
else
|
||||
end
|
||||
end
|
||||
|
@ -85,15 +85,23 @@ module Agents
|
|||
hydra.queue request
|
||||
hydra.run
|
||||
end
|
||||
def update_memory(vals)
|
||||
add_to_memory(vals)
|
||||
cleanup_old_memory
|
||||
end
|
||||
def cleanup_old_memory
|
||||
self.memory["existing_routes"] ||= []
|
||||
self.memory["existing_routes"].reject!{|h| h["currentTime"] <= (Time.now - 2.hours)}
|
||||
end
|
||||
def add_to_memory(vals)
|
||||
self.memory["existing_routes"] ||= []
|
||||
self.memory["existing_routes"] << {stopTag: vals["stopTag"], tripTag: vals["prediction"]["tripTag"], epochTime: vals["prediction"]["epochTime"], currentTime: Time.now}
|
||||
end
|
||||
def not_already_in_memory?(vals)
|
||||
m = self.memory["existing_routes"]
|
||||
m.select{|h| h[:stopTag] == vals["stopTag"] &&
|
||||
h[:tripTag] == vals["prediction"]["tripTag"] &&
|
||||
h[:epochTime] == vals["prediction"]["epochTime"]
|
||||
m.select{|h| h['stopTag'] == vals["stopTag"] &&
|
||||
h['tripTag'] == vals["prediction"]["tripTag"] &&
|
||||
h['epochTime'] == vals["prediction"]["epochTime"]
|
||||
}.count == 0
|
||||
end
|
||||
def default_options
|
||||
|
|
Loading…
Add table
Reference in a new issue