
On Fri, Nov 06, 2020 at 09:10:06AM +0800, Ren Wen wrote:
There are three steps when updating cluster state: 1) get cluster state from redis. 2) update cluster state. 3) rewrite to redis.
Before: write to redis one job info once. After: write to redis more than one job info once.
It will save time when writing more than one job info once.
Signed-off-by: Ren Wen <15991987063@163.com> --- src/lib/sched.cr | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/src/lib/sched.cr b/src/lib/sched.cr index a4b12b4..bff6090 100644 --- a/src/lib/sched.cr +++ b/src/lib/sched.cr @@ -58,11 +58,11 @@ class Sched return cluster_state end
- # get -> modify -> set - def update_cluster_state(cluster_id, job_id, property, value) + # Update job info according to cluster id. + def update_cluster_state(cluster_id, job_id, job_info : Hash(String, String)) cluster_state = get_cluster_state(cluster_id) if cluster_state[job_id]? - cluster_state[job_id].merge!({property => value}) + cluster_state[job_id].merge!(job_info) @redis.hash_set("sched/cluster_state", cluster_id, cluster_state.to_json) end end @@ -86,9 +86,9 @@ class Sched case request_state when "abort", "finished", "failed" # update node state only - update_cluster_state(cluster_id, job_id, "state", states[request_state]) + update_cluster_state(cluster_id, job_id, {"state" => states[request_state]}) ^ ^ add a space after '{' and before '}' in hash table, rubocop request so.
Thanks, Yuanchao