From b949278d1b2badce0cd8eb435544f5b3e9ac7e7b Mon Sep 17 00:00:00 2001 From: Denver Gingerich Date: Sun, 19 Apr 2020 20:36:19 +0000 Subject: [PATCH] fix day total increment, add archived_message save Fix incrementing of the daily message total so that it doesn't use the EMPromise-style code imported in 07bcf9c - this code works elsewhere, but we're not using EMPromise in this file so use the more sequential method of coding (that works here) instead. Also add the saving of the passed-on messages to the archived_message keys. This is done with the 3-day (259,200 seconds) expiration per the just-removed comment. The code as of this commit has been tested now, so it does actually run - the previously version (in 07bcf9c) did not run due to the aforementioned EMPromise issue. --- r2s-bwmsgsv2.rb | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/r2s-bwmsgsv2.rb b/r2s-bwmsgsv2.rb index bca221bc405adfd5a5ce36559d08e17c89883d3c..4122153b3af6f696583ca38d5d82de58865a4a27 100755 --- a/r2s-bwmsgsv2.rb +++ b/r2s-bwmsgsv2.rb @@ -59,17 +59,17 @@ while true day_msg_count = redis.incr( "archived_message-#{ARGV[0]}-#{tai_yyyymmdd}-total" - ).then { |total| + ) - t = Time.now - puts "LOG %d.%09d: total msgs for %s-%s now at %s\n" % - [t.to_i, t.nsec, tai_yyyymmdd, ARGV[0], total] - } + t = Time.now + puts "LOG %d.%09d: total msgs for %s-%s now at %s\n" % + [t.to_i, t.nsec, tai_yyyymmdd, ARGV[0], day_msg_count] # TODO: do something with day_msg_count # TODO: print less stuff in here puts "TODO - got some stuff: " + timestamps_plus_json_blob + puts "TODO - daymsgcount: '#{day_msg_count}'" # add some timestamps to timestamps_plus_json_blob (our own) @@ -86,8 +86,15 @@ while true # if got HTTP 200, then: - # redis.set(...) with expiration of 3 days, including timestamps - # use key: archived_message-#{ARGV[0]}-#{tai_yyyymmdd}-#{day_msg_count} + # TODO: "archived_message-#{ARGV[0]}-#{tai_yyyymmdd}-#{day_msg_count}"? + # if exists, then fail, and leave thing on pending queue (not atomic) + + rv1 = redis.setex( + "archived_message-#{ARGV[0]}-#{tai_yyyymmdd}-#{day_msg_count}", + 259200, timestamps_plus_json_blob + ) + puts "TODO - rv1: " + rv1 + # TODO: confirm rv1 == 'OK' # confirm pending key has one element and e == timestamps_plus_json_blob # if so, then rpop pending_messages-#{ARGV[0]} and discard