Skip to content

Commit

Permalink
Merge pull request #88 from TogetherCrew/fastapi
Browse files Browse the repository at this point in the history
feat: Payload persist handling the case of document being available!
  • Loading branch information
amindadgar authored Nov 4, 2024
2 parents db72e35 + 88a2eb5 commit 0589d41
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions utils/persist_payload.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,24 @@ def persist_http(self, payload: HTTPPayload, update: bool = False) -> None:
f"{community_id} persisted successfully!"
)
else:
# Check if createdAt needs to be set if it doesn't exist
self.client[self.db][self.external_msgs_collection].update_one(
{"taskId": payload.taskId, "createdAt": {"$exists": False}},
{
"$set": {
"createdAt": datetime.now().replace(tzinfo=timezone.utc)
}
},
)

# Update or upsert the main document
self.client[self.db][self.external_msgs_collection].update_one(
{"taskId": payload.taskId},
{
"$set": {
"response": payload.response.model_dump(),
**payload.model_dump(),
"updatedAt": datetime.now().replace(tzinfo=timezone.utc),
},
"$setOnInsert": {
"createdAt": datetime.now().replace(tzinfo=timezone.utc),
},
}
},
upsert=True,
)
Expand Down

0 comments on commit 0589d41

Please sign in to comment.