Skip to content

Commit

Permalink
Merge pull request #6 from mraspaud/fix-logging
Browse files Browse the repository at this point in the history
Log info when a message is sent
  • Loading branch information
mraspaud authored Apr 19, 2024
2 parents cd6480c + ed8bd3a commit 6dac5d5
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
7 changes: 6 additions & 1 deletion src/pytroll_watchers/publisher.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
"""Common functions for publishing messages."""

import datetime
import json
import logging
from contextlib import closing, suppress
from copy import deepcopy

from posttroll.message import Message
from posttroll.publisher import create_publisher_from_dict_config
from trollsift import parse

logger = logging.getLogger(__name__)


def file_publisher_from_generator(generator, publisher_config, message_config):
"""Publish files coming from local filesystem events.
Expand All @@ -26,11 +30,12 @@ def file_publisher_from_generator(generator, publisher_config, message_config):
amended_message_config = deepcopy(message_config)
amended_message_config["data"]["uri"] = file_item.as_uri()
with suppress(AttributeError):
amended_message_config["data"]["fs"] = file_item.fs.to_json()
amended_message_config["data"]["fs"] = json.loads(file_item.fs.to_json())
aliases = amended_message_config.pop("aliases", {})
apply_aliases(aliases, file_metadata)
amended_message_config["data"].update(file_metadata)
msg = Message(**amended_message_config)
logger.info(f"Sending {str(msg)}")
publisher.send(str(msg))


Expand Down
4 changes: 2 additions & 2 deletions tests/test_bucket_notification_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,8 @@ def test_publish_paths(patched_bucket_listener, caplog): # noqa
message = Message(rawstr=messages[0])
assert message.data["uri"] == "s3://viirs-data/sdr/SVM13_npp_d20240408_t1006227_e1007469_b64498_c20240408102334392250_cspp_dev.h5"
assert message.data["sensor"] == "viirs"
assert message.data["fs"] == ('{"cls": "s3fs.core.S3FileSystem", "protocol": "s3", "args": [], '
'"profile": "someprofile"}')
assert message.data["fs"] == {"cls": "s3fs.core.S3FileSystem", "protocol": "s3", "args": [],
"profile": "someprofile"}
assert "Starting watch on 'viirs-data'" in caplog.text


Expand Down
4 changes: 2 additions & 2 deletions tests/test_copernicus_dataspace_watcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,6 @@ def test_publish_paths(caplog):
message = Message(rawstr=messages[0])
assert message.data["uri"] == "s3:///eodata/Sentinel-3/OLCI/OL_1_EFR___/2024/04/15/S3B_OL_1_EFR____20240415T074029_20240415T074329_20240415T094236_0179_092_035_1620_PS2_O_NR_003.SEN3"
assert message.data["sensor"] == "olci"
assert message.data["fs"] == ('{"cls": "s3fs.core.S3FileSystem", "protocol": "s3", "args": [], '
'"profile": "someprofile"}')
assert message.data["fs"] == {"cls": "s3fs.core.S3FileSystem", "protocol": "s3", "args": [],
"profile": "someprofile"}
assert f"Starting watch on dataspace for '{filter_string}'" in caplog.text

0 comments on commit 6dac5d5

Please sign in to comment.