Use a hash to save the mapping between "query" and "ws". When call function "add_filter_rule" will change the "query". If query={"job_id": "1"}, will change to "query={"job_id": ["1"]}". So need to use the modified query to delete the key-value pair in the hash.
Signed-off-by: Wu Zhende wuzhende666@163.com --- src/monitoring/filter.cr | 2 ++ src/monitoring/monitoring.cr | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-)
diff --git a/src/monitoring/filter.cr b/src/monitoring/filter.cr index 8e672e0..5d3bc8b 100644 --- a/src/monitoring/filter.cr +++ b/src/monitoring/filter.cr @@ -16,6 +16,8 @@ class Filter
@hash[query] = Array(HTTP::WebSocket).new unless @hash[query]? @hash[query] << socket + + return query end
private def convert_hash_value_to_array(query) diff --git a/src/monitoring/monitoring.cr b/src/monitoring/monitoring.cr index dff1902..d09c363 100644 --- a/src/monitoring/monitoring.cr +++ b/src/monitoring/monitoring.cr @@ -19,7 +19,7 @@ module Monitoring # also can be {"job_id": ["1", "2"]} query = JSON.parse(msg) if query.as_h? - filter.add_filter_rule(query, socket) + query = filter.add_filter_rule(query, socket) end end