Skip to content

Commit

Permalink
log each event id we process from onclusive
Browse files Browse the repository at this point in the history
so we can check logs in case some event is missing

CPCN-380
  • Loading branch information
petrjasek committed Oct 12, 2023
1 parent 4d884f3 commit 386f2f9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 22 deletions.
46 changes: 25 additions & 21 deletions server/planning/feed_parsers/onclusive.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,34 @@ def can_parse(self, content):

def parse(self, content, provider=None):
all_events = []
with open("/tmp/onclusive.txt", "+a") as debug_output:
for event in content:
print(event["itemId"], event["startDate"], event["summary"], file=debug_output)
for event in content:
logger.info(
"Parsing event id=%s updated=%s deleted=%s",
event["itemId"],
event["lastEditDateUtc"].split(".")[0],
event["deleted"],
)

guid = "urn:onclusive:{}".format(event["itemId"])
guid = "urn:onclusive:{}".format(event["itemId"])

item = {
GUID_FIELD: guid,
ITEM_TYPE: CONTENT_TYPE.EVENT,
"state": CONTENT_STATE.INGESTED,
}
item = {
GUID_FIELD: guid,
ITEM_TYPE: CONTENT_TYPE.EVENT,
"state": CONTENT_STATE.INGESTED,
}

try:
self.set_occur_status(item)
self.parse_item_meta(event, item)
self.parse_location(event, item)
self.parse_event_details(event, item)
self.parse_category(event, item)
self.parse_contact_info(event, item)
all_events.append(item)
except EmbargoedException:
logger.info("Ignoring embargoed event %s", event["itemId"])
except Exception as error:
logger.exception("error %s when parsing event %s", error, event["itemId"], extra=dict(event=event))
try:
self.set_occur_status(item)
self.parse_item_meta(event, item)
self.parse_location(event, item)
self.parse_event_details(event, item)
self.parse_category(event, item)
self.parse_contact_info(event, item)
all_events.append(item)
except EmbargoedException:
logger.info("Ignoring embargoed event %s", event["itemId"])
except Exception as error:
logger.exception("error %s when parsing event %s", error, event["itemId"], extra=dict(event=event))
return all_events

def set_occur_status(self, item):
Expand Down
7 changes: 6 additions & 1 deletion server/planning/feed_parsers/onclusive_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ def setUp(self):
self.parse("onclusive_sample.json")

def test_content(self):
item = OnclusiveFeedParser().parse([self.data])[0]
with self.assertLogs("planning", level=logging.INFO) as logger:
item = OnclusiveFeedParser().parse([self.data])[0]
self.assertIn(
"INFO:planning.feed_parsers.onclusive:Parsing event id=4112034 updated=2022-05-10T12:14:34 deleted=False",
logger.output,
)
item["subject"].sort(key=lambda i: i["name"])
expected_subjects = [
{"name": "Law & Order", "qcode": "88", "scheme": "onclusive_categories"},
Expand Down

0 comments on commit 386f2f9

Please sign in to comment.