Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Geo Message Query TTL Bug Fix #72

Merged
merged 1 commit into from
May 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions services/addons/images/geo_msg_query/geo_msg_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,11 +116,19 @@ def watch_collection(db, input_collection, output_collection):
msg_type = input_collection.replace("Ode", "").replace("Json", "")
logging.info(f"Watching collection: {input_collection}")
count = 0
with db[input_collection].watch() as stream:
with db[input_collection].watch(full_document="updateLookup") as stream:
for change in stream:
count += 1
process_message(change["fullDocument"], db, output_collection, msg_type)
logging.debug(f"{msg_type} Count: {count}")
if change.get("operationType") in ["insert"]:
count += 1
logging.debug(f"Change: {change}")
process_message(
change["fullDocument"], db, output_collection, msg_type
)
logging.debug(f"{msg_type} Count: {count}")
else:
logging.debug(
f"Ignoring change with operationType: {change.get('operationType')}"
)
except Exception as e:
logging.error(
f"An error occurred while watching collection: {input_collection}"
Expand Down
29 changes: 28 additions & 1 deletion services/addons/tests/geo_msg_query/test_geo_query.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,10 @@ def test_watch_collection_success(mock_process_message, mock_logging):
mock_db = MagicMock()
mock_input_collection = "OdeBsmJson"
mock_output_collection = "GeoMsg"
mock_change = {"fullDocument": {"message": "Test message"}}
mock_change = {
"fullDocument": {"message": "Test message"},
"operationType": "insert",
}
mock_stream = MagicMock()
mock_stream.__iter__.return_value = [mock_change]
mock_db.__getitem__.return_value.watch.return_value.__enter__.return_value = (
Expand All @@ -245,6 +248,30 @@ def test_watch_collection_success(mock_process_message, mock_logging):
mock_logging.assert_any_call("Bsm Count: 1")


@patch("logging.debug")
@patch("addons.images.geo_msg_query.geo_msg_query.process_message")
def test_watch_collection_ttl_ignore(mock_process_message, mock_logging):
geo_msg_query.process_message = mock_process_message

mock_db = MagicMock()
mock_input_collection = "OdeBsmJson"
mock_output_collection = "GeoMsg"
mock_change = {
"operationType": "delete",
}
mock_stream = MagicMock()
mock_stream.__iter__.return_value = [mock_change]
mock_db.__getitem__.return_value.watch.return_value.__enter__.return_value = (
mock_stream
)

geo_msg_query.watch_collection(
mock_db, mock_input_collection, mock_output_collection
)

mock_logging.assert_any_call(f"Ignoring change with operationType: delete")


@patch("logging.error")
def test_watch_collection_exception(mock_logging):
mock_db = MagicMock()
Expand Down
Loading