Skip to content

Commit

Permalink
Add todo for datetime deprecation
Browse files Browse the repository at this point in the history
  • Loading branch information
soapy1 committed Dec 11, 2024
1 parent cad48b9 commit 9cd93ef
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 0 deletions.
4 changes: 4 additions & 0 deletions conda-store-server/conda_store_server/_internal/orm.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ def __init__(self, specification, is_lockfile: bool = False):
name: Mapped[str] = mapped_column(Unicode(255), nullable=False)
spec: Mapped[dict] = mapped_column(JSON, nullable=False)
sha256: Mapped[str] = mapped_column(Unicode(255), unique=True, nullable=False)
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
created_on: Mapped[datetime.datetime] = mapped_column(
DateTime, default=datetime.datetime.utcnow
)
Expand Down Expand Up @@ -206,6 +207,7 @@ class Solve(Base):
specification: Mapped["Specification"] = relationship(back_populates="solves")

scheduled_on: Mapped[datetime.datetime] = mapped_column(
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
DateTime, default=datetime.datetime.utcnow
)
started_on: Mapped[datetime.datetime] = mapped_column(DateTime, default=None)
Expand Down Expand Up @@ -259,6 +261,7 @@ class Build(Base):
status_info: Mapped[str] = mapped_column(UnicodeText, default=None)
size: Mapped[int] = mapped_column(BigInteger, default=0)
scheduled_on: Mapped[datetime.datetime] = mapped_column(
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
DateTime, default=datetime.datetime.utcnow
)
started_on: Mapped[datetime.datetime] = mapped_column(DateTime, default=None)
Expand Down Expand Up @@ -721,6 +724,7 @@ def update_packages(self, db, subdirs=None):

logger.info(f"DONE for architecture : {architecture}")

# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
self.last_update = datetime.datetime.utcnow()
db.commit()
logger.info("update packages DONE ")
Expand Down
1 change: 1 addition & 0 deletions conda-store-server/conda_store_server/_internal/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

def _datetime_factory(offset: datetime.timedelta):
"""Utcnow datetime + timezone as string"""
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
return datetime.datetime.utcnow() + offset


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def append_to_logs(db: Session, conda_store, build, logs: typing.Union[str, byte

def set_build_started(db: Session, build: orm.Build):
build.status = schema.BuildStatus.BUILDING
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
build.started_on = datetime.datetime.utcnow()
db.commit()

Expand All @@ -82,6 +83,7 @@ def set_build_failed(
):
build.status = schema.BuildStatus.FAILED
build.status_info = status_info
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
build.ended_on = datetime.datetime.utcnow()
db.commit()

Expand All @@ -91,12 +93,14 @@ def set_build_canceled(
):
build.status = schema.BuildStatus.CANCELED
build.status_info = status_info
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
build.ended_on = datetime.datetime.utcnow()
db.commit()


def set_build_completed(db: Session, conda_store, build: orm.Build):
build.status = schema.BuildStatus.COMPLETED
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
build.ended_on = datetime.datetime.utcnow()

directory_build_artifact = orm.BuildArtifact(
Expand Down Expand Up @@ -156,6 +160,7 @@ def build_cleanup(
builds = api.list_builds(db, status=schema.BuildStatus.BUILDING)

for build in builds:
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
if (
build.status == schema.BuildStatus.BUILDING
and str(build.id) not in build_active_tasks
Expand Down Expand Up @@ -193,6 +198,7 @@ def build_conda_environment(db: Session, conda_store, build):
db,
conda_store,
build,
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
f"starting build of conda environment {datetime.datetime.utcnow()} UTC\n",
)

Expand Down Expand Up @@ -337,6 +343,7 @@ def build_conda_environment(db: Session, conda_store, build):


def solve_conda_environment(db: Session, conda_store, solve: orm.Solve):
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
solve.started_on = datetime.datetime.utcnow()
db.commit()

Expand All @@ -353,6 +360,7 @@ def solve_conda_environment(db: Session, conda_store, solve: orm.Solve):
solve_id=solve.id,
)

# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
solve.ended_on = datetime.datetime.utcnow()
db.commit()

Expand Down
3 changes: 3 additions & 0 deletions conda-store-server/conda_store_server/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,7 @@ def delete_namespace(self, db: Session, namespace: str):
if namespace is None:
raise utils.CondaStoreError(f"namespace={namespace} does not exist")

# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
utcnow = datetime.datetime.utcnow()
namespace.deleted_on = utcnow
for environment_orm in namespace.environments:
Expand Down Expand Up @@ -846,6 +847,7 @@ def delete_environment(self, db: Session, namespace: str, name: str):
f"environment namespace={namespace} name={name} does not exist"
)

# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
utcnow = datetime.datetime.utcnow()
environment.deleted_on = utcnow
for build in environment.builds:
Expand Down Expand Up @@ -877,6 +879,7 @@ def delete_build(self, db: Session, build_id: int):
"cannot delete build since not finished building"
)

# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
build.deleted_on = datetime.datetime.utcnow()
db.commit()

Expand Down
1 change: 1 addition & 0 deletions conda-store-server/conda_store_server/server/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ async def post_login_method(
samesite="strict",
domain=self.cookie_domain,
# set cookie to expire at same time as jwt
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
max_age=int(
(authentication_token.exp - datetime.datetime.utcnow()).total_seconds()
),
Expand Down
1 change: 1 addition & 0 deletions conda-store-server/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ def seed_conda_store(db, conda_store):

# for testing purposes make build 4 complete
build = api.get_build(db, build_id=4)
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
build.started_on = datetime.datetime.utcnow()
build.ended_on = datetime.datetime.utcnow()
build.status = schema.BuildStatus.COMPLETED
Expand Down
1 change: 1 addition & 0 deletions conda-store-server/tests/server/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ def test_expired_token():
token = authentication.encrypt_token(
AuthenticationToken(
primary_namespace="default",
# TODO: change to datetime.datetime.now(datetime.UTC) when python 3.10 is dropped
exp=datetime.datetime.utcnow() - datetime.timedelta(hours=1),
role_bindings={
"default/*": ["viewer"],
Expand Down

0 comments on commit 9cd93ef

Please sign in to comment.