Skip to content

Commit

Permalink
Refactoring, adding json validation method
Browse files Browse the repository at this point in the history
  • Loading branch information
MarkhamLee committed Mar 8, 2024
1 parent 9c39b3b commit 600796b
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion etl_pipelines/etl_library/general_utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import requests
import os
from jsonschema import validate
from etl_library.logging_util import logger # noqa: E402

# load Slack Webhook URL for sending pipeline failure alerts
Expand All @@ -17,6 +18,21 @@ def __init__(self):

pass

@staticmethod
def validate_json(data: dict, schema: dict) -> int:

# validate the data
try:
validate(instance=data, schema=schema)
return 0

except Exception as e:
message = (f'Data validation failed for the pipeline for openweather current, with error: {e}') # noqa: E501
logger.debug(message)
response = EtlUtilities.send_slack_webhook(WEBHOOK_URL, message)
logger.debug(f'Slack pipeline failure alert sent with code: {response}') # noqa: E501
return 1, response

@staticmethod
def send_slack_webhook(url: str, message: str):

Expand Down Expand Up @@ -61,4 +77,3 @@ def generic_post_request(payload: dict, url: str):
except Exception as e:
message = (f'post request failed with error: {e}')
logger.debug(message)
# EtlUtilities.send_slack_webhook(WEBHOOK_URL, message)

0 comments on commit 600796b

Please sign in to comment.