Skip to content

Commit

Permalink
refactor: make timestamp in local tz
Browse files Browse the repository at this point in the history
  • Loading branch information
cbini committed Jan 11, 2024
1 parent 11706b1 commit a8c4dde
Show file tree
Hide file tree
Showing 12 changed files with 40 additions and 16 deletions.
3 changes: 2 additions & 1 deletion src/teamster/core/powerschool/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
def build_powerschool_table_asset(
code_location,
asset_name,
local_timezone,
partitions_def: (
FiscalYearPartitionsDefinition | MonthlyPartitionsDefinition | None
) = None,
Expand All @@ -40,7 +41,7 @@ def _asset(
ssh_powerschool: SSHResource,
db_powerschool: OracleResource,
):
now = pendulum.now().start_of("hour")
now = pendulum.now(tz=local_timezone).start_of("hour")

asset_metadata = context.assets_def.metadata_by_key[context.assets_def.key]

Expand Down
6 changes: 2 additions & 4 deletions src/teamster/core/powerschool/schedules.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,8 @@ def _schedule(
"partition_column"
]

latest_materialization_fmt = (
latest_materialization_datetime.in_timezone(
execution_timezone
).format("YYYY-MM-DDTHH:mm:ss.SSSSSS")
latest_materialization_fmt = latest_materialization_datetime.format(
"YYYY-MM-DDTHH:mm:ss.SSSSSS"
)

[(count,)] = db_powerschool.engine.execute_query(
Expand Down
4 changes: 2 additions & 2 deletions src/teamster/core/powerschool/sensors.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ def _sensor(
) # type: ignore
)

window_start_fmt = latest_materialization_datetime.format(
latest_materialization_fmt = latest_materialization_datetime.format(
"YYYY-MM-DDTHH:mm:ss.SSSSSS"
)

Expand All @@ -71,7 +71,7 @@ def _sensor(
"SELECT COUNT(*) "
f"FROM {asset.key.path[-1]} "
f"WHERE {partition_column} >= "
f"TO_TIMESTAMP('{window_start_fmt}', "
f"TO_TIMESTAMP('{latest_materialization_fmt}', "
"'YYYY-MM-DD\"T\"HH24:MI:SS.FF6')"
),
partition_size=1,
Expand Down
3 changes: 2 additions & 1 deletion src/teamster/kippcamden/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pendulum
from pendulum.tz import timezone

from teamster.core.utils.classes import FiscalYear

CODE_LOCATION = "kippcamden"

LOCAL_TIMEZONE = pendulum.timezone(name="America/New_York")
LOCAL_TIMEZONE = timezone(name="America/New_York")
NOW = pendulum.now(tz=LOCAL_TIMEZONE)
TODAY = NOW.start_of(unit="day")
CURRENT_FISCAL_YEAR = FiscalYear(datetime=TODAY, start_month=7)
4 changes: 4 additions & 0 deletions src/teamster/kippcamden/powerschool/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
build_powerschool_table_asset(
**asset,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
op_tags={MAX_RUNTIME_SECONDS_TAG: (60 * 10)},
)
for asset in config_from_files([(f"{config_dir}/assets-full.yaml")])["assets"]
Expand All @@ -25,6 +26,7 @@
build_powerschool_table_asset(
**asset,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
op_tags={MAX_RUNTIME_SECONDS_TAG: (60 * 10)},
)
for asset in config_from_files([(f"{config_dir}/assets-nonpartition.yaml")])[
Expand All @@ -36,6 +38,7 @@
build_powerschool_table_asset(
**asset,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
partitions_def=FiscalYearPartitionsDefinition(
start_date=pendulum.datetime(year=2016, month=7, day=1),
start_month=7,
Expand All @@ -54,6 +57,7 @@
build_powerschool_table_asset(
**asset,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
partitions_def=MonthlyPartitionsDefinition(
start_date=pendulum.datetime(year=2016, month=7, day=1),
timezone=LOCAL_TIMEZONE.name,
Expand Down
3 changes: 2 additions & 1 deletion src/teamster/kippmiami/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pendulum
from pendulum.tz import timezone

from teamster.core.utils.classes import FiscalYear

CODE_LOCATION = "kippmiami"

LOCAL_TIMEZONE = pendulum.timezone(name="America/New_York")
LOCAL_TIMEZONE = timezone(name="America/New_York")
NOW = pendulum.now(tz=LOCAL_TIMEZONE)
TODAY = NOW.start_of(unit="day")
CURRENT_FISCAL_YEAR = FiscalYear(datetime=TODAY, start_month=7)
11 changes: 9 additions & 2 deletions src/teamster/kippmiami/powerschool/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@
config_dir = f"src/teamster/{CODE_LOCATION}/powerschool/config"

full_assets = [
build_powerschool_table_asset(**cfg, code_location=CODE_LOCATION)
build_powerschool_table_asset(
**cfg, code_location=CODE_LOCATION, local_timezone=LOCAL_TIMEZONE
)
for cfg in config_from_files([(f"{config_dir}/assets-full.yaml")])["assets"]
]

nonpartition_assets = [
build_powerschool_table_asset(
**cfg, code_location=CODE_LOCATION, op_tags={MAX_RUNTIME_SECONDS_TAG: (60 * 10)}
**cfg,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
op_tags={MAX_RUNTIME_SECONDS_TAG: (60 * 10)},
)
for cfg in config_from_files([(f"{config_dir}/assets-nonpartition.yaml")])["assets"]
]
Expand All @@ -28,6 +33,7 @@
build_powerschool_table_asset(
**asset,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
partitions_def=FiscalYearPartitionsDefinition(
start_date=pendulum.datetime(year=2018, month=7, day=1),
start_month=7,
Expand All @@ -46,6 +52,7 @@
build_powerschool_table_asset(
**asset,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
partitions_def=MonthlyPartitionsDefinition(
start_date=pendulum.datetime(year=2018, month=7, day=1),
timezone=LOCAL_TIMEZONE.name,
Expand Down
3 changes: 2 additions & 1 deletion src/teamster/kippnewark/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pendulum
from pendulum.tz import timezone

from teamster.core.utils.classes import FiscalYear

CODE_LOCATION = "kippnewark"

LOCAL_TIMEZONE = pendulum.timezone(name="America/New_York")
LOCAL_TIMEZONE = timezone(name="America/New_York")
NOW = pendulum.now(tz=LOCAL_TIMEZONE)
TODAY = NOW.start_of(unit="day")
CURRENT_FISCAL_YEAR = FiscalYear(datetime=TODAY, start_month=7)
12 changes: 10 additions & 2 deletions src/teamster/kippnewark/powerschool/assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,20 @@

full_assets = [
build_powerschool_table_asset(
**cfg, code_location=CODE_LOCATION, op_tags={MAX_RUNTIME_SECONDS_TAG: (60 * 10)}
**cfg,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
op_tags={MAX_RUNTIME_SECONDS_TAG: (60 * 10)},
)
for cfg in config_from_files([(f"{config_dir}/assets-full.yaml")])["assets"]
]

nonpartition_assets = [
build_powerschool_table_asset(
**cfg, code_location=CODE_LOCATION, op_tags={MAX_RUNTIME_SECONDS_TAG: (60 * 10)}
**cfg,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
op_tags={MAX_RUNTIME_SECONDS_TAG: (60 * 10)},
)
for cfg in config_from_files([(f"{config_dir}/assets-nonpartition.yaml")])["assets"]
]
Expand All @@ -30,6 +36,7 @@
build_powerschool_table_asset(
**asset,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
partitions_def=FiscalYearPartitionsDefinition(
start_date=pendulum.datetime(year=2016, month=7, day=1),
start_month=7,
Expand All @@ -48,6 +55,7 @@
build_powerschool_table_asset(
**asset,
code_location=CODE_LOCATION,
local_timezone=LOCAL_TIMEZONE,
partitions_def=MonthlyPartitionsDefinition(
start_date=pendulum.datetime(year=2016, month=7, day=1),
timezone=LOCAL_TIMEZONE.name,
Expand Down
3 changes: 2 additions & 1 deletion src/teamster/kipptaf/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pendulum
from pendulum.tz import timezone

from teamster.core.utils.classes import FiscalYear

CODE_LOCATION = "kipptaf"

LOCAL_TIMEZONE = pendulum.timezone(name="America/New_York")
LOCAL_TIMEZONE = timezone(name="America/New_York")
NOW = pendulum.now(tz=LOCAL_TIMEZONE)
TODAY = NOW.start_of(unit="day")
CURRENT_FISCAL_YEAR = FiscalYear(datetime=TODAY, start_month=7)
3 changes: 2 additions & 1 deletion src/teamster/staging/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import pendulum
from pendulum.tz import timezone

from teamster.core.utils.classes import FiscalYear

CODE_LOCATION = "staging"

LOCAL_TIMEZONE = pendulum.timezone(name="America/New_York")
LOCAL_TIMEZONE = timezone(name="America/New_York")
NOW = pendulum.now(tz=LOCAL_TIMEZONE)
TODAY = NOW.start_of(unit="day")
CURRENT_FISCAL_YEAR = FiscalYear(datetime=TODAY, start_month=7)
1 change: 1 addition & 0 deletions tests/assets/test_powerschool_assets.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
def _test_asset(asset_name, partitions_def=None, partition_column=None):
asset = build_powerschool_table_asset(
code_location="staging",
local_timezone=LOCAL_TIMEZONE,
asset_name=asset_name,
partitions_def=partitions_def,
partition_column=partition_column,
Expand Down

0 comments on commit a8c4dde

Please sign in to comment.