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

Record and recall environment creation time. #61

Merged
merged 1 commit into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ type Environment {
state: State
tags: [String!]!
hidden: Boolean!
created: Int!
cachedEnvs: [Environment!]!
interpreters: Interpreters!
requested: DateTime
Expand Down
1 change: 1 addition & 0 deletions softpack_core/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,7 @@ def spec(self) -> Box:
info["tags"] = getattr(metadata, "tags", [])
info["hidden"] = getattr(metadata, "hidden", False)
info["force_hidden"] = getattr(metadata, "force_hidden", False)
info["created"] = getattr(metadata, "created", 0)

info["interpreters"] = Interpreters()

Expand Down
7 changes: 6 additions & 1 deletion softpack_core/schemas/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import statistics
from dataclasses import dataclass, field
from pathlib import Path
from time import time
from traceback import format_exception_only
from typing import List, Optional, Tuple, Union, cast

Expand Down Expand Up @@ -333,6 +334,7 @@ class Environment:
state: Optional[State]
tags: list[str]
hidden: bool
created: int
cachedEnvs: list["Environment"] = field(default_factory=list)
interpreters: Interpreters = field(default_factory=Interpreters)

Expand Down Expand Up @@ -417,6 +419,7 @@ def from_artifact(cls, obj: Artifacts.Object) -> Optional["Environment"]:
type=spec.get("type", ""),
tags=spec.tags,
hidden=spec.hidden,
created=spec.created,
interpreters=spec.get("interpreters", Interpreters()),
)
except KeyError:
Expand Down Expand Up @@ -553,7 +556,9 @@ def create_new_env(
)
definitionData = yaml.dump(softpack_definition)

meta = dict(tags=sorted(set(env.tags or [])))
meta = dict(
tags=sorted(set(env.tags or [])), created=round(time())
)
metaData = yaml.dump(meta)

tree_oid = artifacts.create_files(
Expand Down
6 changes: 6 additions & 0 deletions tests/integration/test_environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import datetime
import io
import json
import time
from pathlib import Path
from typing import Optional

Expand Down Expand Up @@ -78,6 +79,7 @@ def test_create(httpx_post, testable_env_input: EnvironmentInput) -> None:
meta_yml = file_in_remote(dir / artifacts.meta_file)
expected_meta_yml = {"tags": []}
actual_meta_yml = yaml.safe_load(meta_yml.data.decode())
del actual_meta_yml["created"]
assert actual_meta_yml == expected_meta_yml

dir = Path(
Expand All @@ -98,6 +100,7 @@ def test_create(httpx_post, testable_env_input: EnvironmentInput) -> None:
meta_yml = file_in_remote(dir / artifacts.meta_file)
expected_meta_yml = {"tags": ["bar", "foo"]}
actual_meta_yml = yaml.safe_load(meta_yml.data.decode())
del actual_meta_yml["created"]
assert actual_meta_yml == expected_meta_yml

result = Environment.create(testable_env_input)
Expand Down Expand Up @@ -315,7 +318,9 @@ def test_iter_no_statuses(testable_env_input):
@pytest.mark.asyncio
async def test_states(httpx_post, testable_env_input, mocker):
orig_name = testable_env_input.name
startTime = time.time() - 1
result = Environment.create(testable_env_input)
endTime = time.time() + 1
testable_env_input.name = orig_name
assert isinstance(result, CreateEnvironmentSuccess)
httpx_post.assert_called_once()
Expand Down Expand Up @@ -349,6 +354,7 @@ async def test_states(httpx_post, testable_env_input, mocker):
assert any(p.version == "v1.1" for p in env.packages)
assert env.type == Artifacts.built_by_softpack
assert env.state == State.queued
assert env.created >= startTime and env.created <= endTime

upload = UploadFile(
filename=Artifacts.builder_out, file=io.BytesIO(b"some output")
Expand Down
Loading