hehehehehe mek valke wurke
This commit is contained in:
@@ -35,12 +35,6 @@ func InsertOrUpdateEstimatedCall(ctx context.Context, db *sql.DB, values []inter
|
|||||||
key := fmt.Sprintf("%v.%v", estimatedVehicleJourneyID, orderID)
|
key := fmt.Sprintf("%v.%v", estimatedVehicleJourneyID, orderID)
|
||||||
fmt.Printf("Estimated Vehicle Journey ID: %v, Order ID: %v\n", estimatedVehicleJourneyID, orderID)
|
fmt.Printf("Estimated Vehicle Journey ID: %v, Order ID: %v\n", estimatedVehicleJourneyID, orderID)
|
||||||
|
|
||||||
// Set the MD5 hash in Valkey
|
|
||||||
err := valki.SetValkeyValue(ctx, valkeyClient, key, hashString)
|
|
||||||
if err != nil {
|
|
||||||
return 0, "", fmt.Errorf("failed to set value in Valkey: %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the MD5 hash from Valkey
|
// Get the MD5 hash from Valkey
|
||||||
retrievedHash, err := valki.GetValkeyValue(ctx, valkeyClient, key)
|
retrievedHash, err := valki.GetValkeyValue(ctx, valkeyClient, key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -48,10 +42,10 @@ func InsertOrUpdateEstimatedCall(ctx context.Context, db *sql.DB, values []inter
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check if the retrieved value matches the original MD5 hash
|
// Check if the retrieved value matches the original MD5 hash
|
||||||
if retrievedHash != hashString {
|
if retrievedHash == hashString {
|
||||||
return 0, "", fmt.Errorf("hash mismatch: original %s, retrieved %s", hashString, retrievedHash)
|
fmt.Println("Retrieved hash matches the original hash. No update needed.")
|
||||||
|
return 0, "no_update", nil
|
||||||
}
|
}
|
||||||
fmt.Println("Retrieved hash matches the original hash.")
|
|
||||||
|
|
||||||
query := `
|
query := `
|
||||||
INSERT INTO calls (
|
INSERT INTO calls (
|
||||||
@@ -84,5 +78,14 @@ func InsertOrUpdateEstimatedCall(ctx context.Context, db *sql.DB, values []inter
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, "", fmt.Errorf("error executing statement: %v", err)
|
return 0, "", fmt.Errorf("error executing statement: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If the record was inserted or updated, set the new hash in Valkey
|
||||||
|
if action == "insert" || action == "update" {
|
||||||
|
err = valki.SetValkeyValue(ctx, valkeyClient, key, hashString)
|
||||||
|
if err != nil {
|
||||||
|
return 0, "", fmt.Errorf("failed to set value in Valkey: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return id, action, nil
|
return id, action, nil
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user