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

Add exception handling for recent data scraping airflow operators #3607

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

charlie-costanzo
Copy link
Member

@charlie-costanzo charlie-costanzo commented Dec 19, 2024

Description

We recently introduced MVP data syncs of the DOT NTD data portal and the state geodata portal. This PR goes back and introduces the appropriate exception handling to catch unwanted behavior.

Operators impacted:

  • airflow/plugins/operators/scrape_ntd_api.py
  • airflow/plugins/operators/scrape_ntd_xlsx.py
  • airflow/plugins/operators/scrape_state_geoportal.py
  • airflow/dags/sync_ntd_data_xlsx/scrape_ntd_xlsx_urls.py

Type of change

  • New feature

How has this been tested?

Screenshot 2024-12-19 at 1 39 21 PM Screenshot 2024-12-19 at 1 35 49 PM Screenshot 2024-12-19 at 1 31 46 PM

Post-merge follow-ups

  • Actions required (specified below)
    ensure these operators run as expected

@charlie-costanzo charlie-costanzo added the data-pipeline-ingestion-and-modeling Ingesting, parsing and modeling data. Evan Siroky is product owner. label Dec 19, 2024
@charlie-costanzo charlie-costanzo self-assigned this Dec 19, 2024
@charlie-costanzo charlie-costanzo marked this pull request as ready for review December 19, 2024 19:01
@charlie-costanzo charlie-costanzo requested review from mjumbewu and erikamov and removed request for evansiroky and vevetron December 19, 2024 19:01
Copy link
Contributor

@erikamov erikamov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great to have these exception handling!
I added some comments about nested exceptions. I just think it would be easier to read, but let me know what do you think.

req = requests.get(url)
soup = BeautifulSoup(req.text, "html.parser")
for key, url in xlsx_urls.items():
try:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since there are others exception handling on line 44 and 55, could those line be unnested and this other "try" moved to line 60?

Comment on lines +188 to +190
except Exception as e:
logging.error(f"Error in XLSX operator execution: {e}")
raise AirflowException(f"XLSX operator execution failed: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the nested exceptions here, this last one is handling just lines 138 to 154? Maybe could be moved up?

Comment on lines +128 to +130
except Exception as e:
logging.error(f"Error in geoportal data fetch: {e}")
raise AirflowException(f"Failed to fetch geoportal data: {e}")
Copy link
Contributor

@erikamov erikamov Dec 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here?

Comment on lines +252 to +254
except Exception as e:
logging.error(f"Error in geoportal operator execution: {e}")
raise AirflowException(f"Geoportal operator execution failed: {e}")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
data-pipeline-ingestion-and-modeling Ingesting, parsing and modeling data. Evan Siroky is product owner.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants