From f991745d9ad8c6295047f744df2066530baf1d9d Mon Sep 17 00:00:00 2001 From: akadusei Date: Sat, 26 Aug 2023 16:51:31 +0000 Subject: [PATCH] Fix error ``` Invalid Int32: "report description or id here" (ArgumentError) ``` The order of items retrieved from redis is not guaranteed, but the previous implementation assumed it was. --- CHANGELOG.md | 3 +++ src/mel/progress/report.cr | 14 ++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f020146..0bda77b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0. - Set default `.batch_size` to `-100` - Increase default `.poll_interval` to 15 seconds +### Fixed +- Fix `Invalid Int32` error when tracking progress + ## [0.10.0] - 2023-06-01 ### Changed diff --git a/src/mel/progress/report.cr b/src/mel/progress/report.cr index 9c48a1b..b53e402 100644 --- a/src/mel/progress/report.cr +++ b/src/mel/progress/report.cr @@ -10,6 +10,10 @@ struct Mel::Progress @value = value.to_i end + def self.new(hash : Hash) + new(hash["id"], hash["description"], hash["value"]) + end + def started? : Bool moving? end @@ -36,17 +40,11 @@ struct Mel::Progress def self.find(ids : Indexable, redis = nil) : Array(Mel::Progress::Report)? return if ids.empty? - rows = redis ? Query.get(ids, redis) : Query.get(ids) reports = rows.each.map(&.as(Array).map &.as(String)).compact_map do |row| - row[1]?.try do |description| - row[3]?.try do |id| - row[5]?.try do |value| - new(id, description, value) - end - end - end + next unless row.size == 6 + new row.each_slice(2).to_h end.to_a reports unless reports.empty?