spetz commented on code in PR #2579:
URL: https://github.com/apache/iggy/pull/2579#discussion_r2703681059


##########
core/connectors/sinks/postgres_sink/src/lib.rs:
##########
@@ -254,55 +349,351 @@ impl PostgresSink {
             }
 
             if include_origin_timestamp {
-                let origin_timestamp = DateTime::from_timestamp(
-                    (message.origin_timestamp / 1_000_000) as i64,
-                    ((message.origin_timestamp % 1_000_000) * 1_000) as u32,
-                )
-                .unwrap_or_else(Utc::now);
                 query_obj = query_obj.bind(origin_timestamp);
             }
 
-            query_obj = query_obj.bind(payload_bytes);
+            query_obj = match payload_format {
+                PayloadFormat::Bytea => query_obj.bind(payload_bytes.to_vec()),
+                PayloadFormat::Json => query_obj.bind(json_value.clone()),
+                PayloadFormat::Text => query_obj.bind(text_value.clone()),
+            };
+
+            match query_obj.execute(pool).await {
+                Ok(_) => return Ok(()),
+                Err(e) => {
+                    attempts += 1;
+                    handle_retry_error(e, attempts, max_retries)?;
+                    tokio::time::sleep(retry_delay * attempts).await;
+                }
+            }
+        }
+    }
 
-            query_obj.execute(pool).await.map_err(|e| {
-                error!("Failed to insert message: {}", e);
-                Error::InvalidRecord
-            })?;
+    fn get_pool(&self) -> Result<&Pool<Postgres>, Error> {
+        self.pool
+            .as_ref()
+            .ok_or_else(|| Error::InitError("Database not 
connected".to_string()))
+    }
+
+    fn payload_format(&self) -> PayloadFormat {
+        PayloadFormat::from_config(self.config.payload_format.as_deref())
+    }
+
+    fn get_max_retries(&self) -> u32 {
+        self.config.max_retries.unwrap_or(DEFAULT_MAX_RETRIES)
+    }
+
+    fn get_retry_delay(&self) -> Duration {
+        let delay_str = self
+            .config
+            .retry_delay
+            .as_deref()
+            .unwrap_or(DEFAULT_RETRY_DELAY);
+        HumanDuration::from_str(delay_str)
+            .unwrap_or_else(|e| panic!("Invalid retry_delay '{delay_str}': 
{e}"))
+            .into()
+    }

Review Comment:
   I decided that it's better to crash when you explicitly provide an invalid 
configuration than to fall back to the default value while the user thinks it 
works as expected.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to