Skip to content

Commit

Permalink
[BUG] Change date/time parsing in AutosysSensor (#89)
Browse files Browse the repository at this point in the history
* change date/time parsing in AutosysSensor

---------

Co-authored-by: Maxim Mityutko <[email protected]>
  • Loading branch information
maxim-mityutko and Maxim Mityutko authored Feb 16, 2024
1 parent 5a4fdfc commit 399bbea
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Thanks to the contributors who helped on this project apart from the authors
* [Brent (Johnson) Spetner](https://www.linkedin.com/in/brentjohnsoneng/)
* [Dmitrii Grigorev](https://www.linkedin.com/in/dmitrii-grigorev-074739135/)
* [Chanukya Konuganti](https://www.linkedin.com/in/chanukyakonuganti/)
* [Maxim Mityutko](https://www.linkedin.com/in/mityutko/)

# Honorary Mentions
Thanks to the team below for invaluable insights and support throughout the initial release of this project
Expand Down
26 changes: 14 additions & 12 deletions brickflow_plugins/airflow/operators/external_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from requests import HTTPError

from datetime import datetime, timedelta
from dateutil.parser import parse # type: ignore[import-untyped]
import time
import pytz
from brickflow_plugins import log
Expand Down Expand Up @@ -386,28 +387,29 @@ def poke(self, context):
else:
status = response.json()["status"][:2].upper()

timestamp_format = "%Y-%m-%dT%H:%M:%SZ"
lastend = datetime.strptime(
response.json()["lastEndUTC"], timestamp_format
).replace(tzinfo=pytz.UTC)
last_end_timestamp = parse(response.json()["lastEndUTC"]).replace(
tzinfo=pytz.UTC
)

time_delta = (
self.time_delta
if isinstance(self.time_delta, timedelta)
else timedelta(**self.time_delta)
)

execution_date = datetime.strptime(
context["execution_date"], "%Y-%m-%dT%H:%M:%S.%f%z"
)
rundate = execution_date - time_delta
execution_timestamp = parse(str(context["execution_date"]))
run_timestamp = execution_timestamp - time_delta

if "SU" in status and lastend >= rundate:
print(f"Last End: {lastend}, Run Date: {rundate}")
print("Success criteria met. Exiting")
if "SU" in status and last_end_timestamp >= run_timestamp:
logging.info(
f"Last End: {last_end_timestamp}, Run Timestamp: {run_timestamp}"
)
logging.info("Success criteria met. Exiting")
return True
else:
print(f"Last End: {lastend}, Run Date: {rundate}")
logging.info(
f"Last End: {last_end_timestamp}, Run Timestamp: {run_timestamp}"
)
time.sleep(self.poke_interval)
logging.info("Poking again")
AutosysSensor.poke(self, context)

0 comments on commit 399bbea

Please sign in to comment.