Skip to content

Commit e9bb0a7

Browse files
committed
wrapped in try block
1 parent e3e96bf commit e9bb0a7

File tree

1 file changed

+19
-12
lines changed

1 file changed

+19
-12
lines changed

nhsn/delphi_nhsn/pull.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,25 @@
1717

1818
def check_last_updated(socrata_token, dataset_id, logger):
1919
"""Check last updated timestamp to determine data should be pulled or not."""
20-
client = Socrata("data.cdc.gov", socrata_token)
21-
response = client.get_metadata(dataset_id)
22-
23-
updated_timestamp = datetime.utcfromtimestamp(int(response["rowsUpdatedAt"]))
24-
now = datetime.utcnow()
25-
recently_updated_source = (now - updated_timestamp) < timedelta(days=1)
26-
27-
prelim_prefix = "Preliminary " if dataset_id == PRELIM_DATASET_ID else ""
28-
if recently_updated_source:
29-
logger.info(f"{prelim_prefix}NHSN data was recently updated; Pulling data", updated_timestamp=updated_timestamp)
30-
else:
31-
logger.info(f"{prelim_prefix}NHSN data is stale; Skipping", updated_timestamp=updated_timestamp)
20+
recently_updated_source = True
21+
try:
22+
client = Socrata("data.cdc.gov", socrata_token)
23+
response = client.get_metadata(dataset_id)
24+
25+
updated_timestamp = datetime.utcfromtimestamp(int(response["rowsUpdatedAt"]))
26+
now = datetime.utcnow()
27+
recently_updated_source = (now - updated_timestamp) < timedelta(days=1)
28+
29+
prelim_prefix = "Preliminary " if dataset_id == PRELIM_DATASET_ID else ""
30+
if recently_updated_source:
31+
logger.info(
32+
f"{prelim_prefix}NHSN data was recently updated; Pulling data", updated_timestamp=updated_timestamp
33+
)
34+
else:
35+
logger.info(f"{prelim_prefix}NHSN data is stale; Skipping", updated_timestamp=updated_timestamp)
36+
# pylint: disable=W0703
37+
except Exception as e:
38+
logger.info("error while processing socrata metadata; continuing processing", error=str(e))
3239
return recently_updated_source
3340

3441

0 commit comments

Comments
 (0)