From 41958978e37d9d241d0615fc640cb9f9068f3c35 Mon Sep 17 00:00:00 2001 From: David Bonet Date: Sun, 19 Nov 2023 21:28:00 +0100 Subject: [PATCH] fix time conversion --- Cargo.toml | 2 +- src/functions.rs | 16 +++++++++------- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 23953fa..185ebf7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "rsmq_async" -version = "8.0.0" +version = "8.0.1" authors = [ "David Bonet " ] diff --git a/src/functions.rs b/src/functions.rs index 4d5d2c6..a264202 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -19,6 +19,8 @@ lazy_static! { Script::new(include_str!("./redis-scripts/receiveMessage.lua")); } +static JS_COMPAT_MAX_TIME_MILLIS: u64 = 9_999_999_000; + /// The main object of this library. Creates/Handles the redis connection and contains all the methods #[derive(Clone)] pub struct RsmqFunctions { @@ -46,7 +48,7 @@ impl RsmqFunctions { let queue = self.get_queue(conn, qname, false).await?; - number_in_range(hidden, 0, 9_999_999_000)?; + number_in_range(hidden, 0, JS_COMPAT_MAX_TIME_MILLIS)?; CHANGE_MESSAGE_VISIVILITY .key(format!("{}{}", self.ns, qname)) @@ -80,8 +82,8 @@ impl RsmqFunctions { let delay = get_redis_duration(delay, &Duration::ZERO); let maxsize = maxsize.unwrap_or(65536); - number_in_range(hidden, 0, 9_999_999_000)?; - number_in_range(delay, 0, 9_999_999)?; + number_in_range(hidden, 0, JS_COMPAT_MAX_TIME_MILLIS)?; + number_in_range(delay, 0, JS_COMPAT_MAX_TIME_MILLIS)?; if let Err(error) = number_in_range(maxsize, 1024, 65536) { if maxsize != -1 { // TODO: Create another error in order to explain that -1 is allowed @@ -295,7 +297,7 @@ impl RsmqFunctions { let queue = self.get_queue(conn, qname, false).await?; let hidden = get_redis_duration(hidden, &queue.vt); - number_in_range(hidden, 0, 9_999_999_000)?; + number_in_range(hidden, 0, JS_COMPAT_MAX_TIME_MILLIS)?; let result: (bool, String, Vec, u64, u64) = RECEIVE_MESSAGE .key(format!("{}{}", self.ns, qname)) @@ -332,7 +334,7 @@ impl RsmqFunctions { let delay = get_redis_duration(delay, &queue.delay); let key = format!("{}{}", self.ns, qname); - number_in_range(delay, 0, 9_999_999)?; + number_in_range(delay, 0, JS_COMPAT_MAX_TIME_MILLIS)?; let message: RedisBytes = message.into(); @@ -419,7 +421,7 @@ impl RsmqFunctions { if hidden.is_some() { let duration = get_redis_duration(hidden, &Duration::from_secs(30)); - number_in_range(duration, 0, 9_999_999_000)?; + number_in_range(duration, 0, JS_COMPAT_MAX_TIME_MILLIS)?; commands = commands .cmd("HSET") .arg(&queue_name) @@ -429,7 +431,7 @@ impl RsmqFunctions { if delay.is_some() { let delay = get_redis_duration(delay, &Duration::ZERO); - number_in_range(delay, 0, 9_999_999)?; + number_in_range(delay, 0, JS_COMPAT_MAX_TIME_MILLIS)?; commands = commands .cmd("HSET") .arg(&queue_name)