Skip to content

Commit ad01adc

Browse files
committed
message listener now gets files, need to test if it works with extractors
1 parent f84f225 commit ad01adc

File tree

2 files changed

+10
-13
lines changed

2 files changed

+10
-13
lines changed

backend/app/routers/files.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ async def add_file_entry(
148148

149149
message_body = {
150150
"event_type": "file_indexed",
151-
"file_data": json.loads(new_file.json()), # This handles ObjectID serialization
151+
"file_data": json.loads(new_file.json()),
152+
"user": json.loads(user.json()),# This handles ObjectID serialization
152153
"timestamp": datetime.now().isoformat()
153154
}
154155

@@ -189,7 +190,8 @@ async def add_local_file_entry(
189190
# Publish a message when indexing is complete
190191
message_body = {
191192
"event_type": "file_indexed",
192-
"file_data": json.loads(new_file.json()), # This handles ObjectID serialization
193+
"file_data": json.loads(new_file.json()),
194+
"user": json.loads(user.json()),# This handles ObjectID serialization
193195
"timestamp": datetime.now().isoformat()
194196
}
195197

backend/message_listener.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -96,32 +96,26 @@ def parse_message_status(msg):
9696
return {"status": EventListenerJobStatus.PROCESSING, "cleaned_msg": msg}
9797

9898

99-
async def callback(message: AbstractIncomingMessage):
100-
"""This method receives messages from RabbitMQ and processes them.
101-
the extractor info is parsed from the message and if the extractor is new
102-
or is a later version, the db is updated.
103-
"""
99+
async def callback(message: AbstractIncomingMessage, es, rabbitmq_client):
100+
"""This method receives messages from RabbitMQ and processes them."""
104101
async with message.process():
105102
msg = json.loads(message.body.decode("utf-8"))
106103

107104
if "event_type" in msg and msg["event_type"] == "file_indexed":
108105
logger.info(f"This is an event type file indexed!")
109-
msg = json.loads(message.body.decode("utf-8"))
110106

111107
# Convert string IDs back to PydanticObjectId if needed
112108
file_data = msg.get("file_data", {})
113-
user = msg.get("user", {})
114-
if "id" in file_data and isinstance(file_data["id"], str):
115-
file_data["id"] = PydanticObjectId(file_data["id"])
109+
user_data = msg.get("user", {}) # Fixed variable name
116110

117111
if "id" in file_data and isinstance(file_data["id"], str):
118112
file_data["id"] = PydanticObjectId(file_data["id"])
119113

120-
# Create FileOut object
114+
# Create FileOut object
121115
file_out = FileOut(**file_data)
122116

123117
# Create UserOut object from the user data in the message
124-
user = UserOut(**user_data)
118+
user = UserOut(**user_data) # Use user_data, not user
125119

126120
# Now call check_feed_listeners with the injected dependencies
127121
await check_feed_listeners(
@@ -130,6 +124,7 @@ async def callback(message: AbstractIncomingMessage):
130124
user,
131125
rabbitmq_client, # RabbitMQ client
132126
)
127+
return True
133128

134129
else:
135130
job_id = msg["job_id"]

0 commit comments

Comments
 (0)