Skip to content

Commit

Permalink
set expiry when parsing onclusive events
Browse files Browse the repository at this point in the history
CPCN-825
  • Loading branch information
petrjasek committed Jun 4, 2024
1 parent d2e730e commit f54ffa1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions server/planning/feed_parsers/onclusive.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def parse(self, content, provider=None):
self.parse_event_details(event, item)
self.parse_category(event, item)
self.parse_contact_info(event, item)
self.set_expiry(item, provider)
all_events.append(item)
except EmbargoedException:
logger.info("Ignoring embargoed event %s", event["itemId"])
Expand Down Expand Up @@ -303,3 +304,11 @@ def parse_contact_info(self, event, item):
existing_contact_id = bson.ObjectId(existing_contact["_id"])
get_resource_service("contacts").patch(existing_contact_id, data)
item["event_contact_info"].append(existing_contact_id)

def set_expiry(self, event, provider) -> None:
expiry_minutes = (
int(provider.get("content_expiry") if provider else 0)
or int(app.config.get("INGEST_EXPIRY_MINUTES"))
or (60 * 24)
)
event["expiry"] = event["dates"]["end"] + datetime.timedelta(minutes=(expiry_minutes))
2 changes: 2 additions & 0 deletions server/planning/feed_parsers/onclusive_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ def test_content(self):
item = OnclusiveFeedParser().parse([data])[0]
self.assertEqual(item["occur_status"]["qcode"], "eocstat:eos3")

self.assertGreater(item["expiry"], item["dates"]["end"])

def test_content_no_time(self):
data = self.data.copy()
data["time"] = ""
Expand Down

0 comments on commit f54ffa1

Please sign in to comment.