Skip to content

Commit

Permalink
fix: Reset attempts when complete
Browse files Browse the repository at this point in the history
  • Loading branch information
karatugo committed Sep 26, 2024
1 parent 3a93f45 commit f31260d
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions sumstats_service/resources/mongo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,24 +179,34 @@ def insert_or_update_metadata_yaml_request(
):

print(f"adding {gcst_id} with hm: {is_harmonised} to yaml")

update_doc = {
"$set": {
"request_updated": datetime.now(),
"status": status.value,
"additional_info": additional_info,
},
"$setOnInsert": {
"request_created": datetime.now(),
"globus_endpoint_id": globus_endpoint_id,
"attempts": 0,
},
}

# If status is COMPLETED, then reset attempts to 0.
# Otherwise increment attempts.
if status == config.MetadataYamlStatus.COMPLETED:
update_doc["$set"]["attempts"] = 0
else:
update_doc["$inc"] = {"attempts": 1}

# Perform the update
self.metadata_yaml_collection.update_one(
{
"gcst_id": gcst_id,
"is_harmonised": is_harmonised,
},
{
"$set": {
"request_updated": datetime.now(),
"status": status.value,
"additional_info": additional_info,
},
"$setOnInsert": {
"request_created": datetime.now(),
"globus_endpoint_id": globus_endpoint_id,
"attempts": 0,
},
"$inc": {"attempts": 1},
},
update_doc,
upsert=True,
)
print(f"Metadata YAML request for {gcst_id} inserted or updated.")
Expand Down

0 comments on commit f31260d

Please sign in to comment.