Skip to content

Commit

Permalink
Keep track of when artefacts updates, not the environments list.
Browse files Browse the repository at this point in the history
  • Loading branch information
mjkw31 committed Sep 10, 2024
1 parent ae7fb75 commit ad9bce0
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 deletions.
2 changes: 2 additions & 0 deletions softpack_core/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Artifacts:
users_folder_name = "users"
groups_folder_name = "groups"
credentials_callback = None
updated = True

@dataclass
class Object:
Expand Down Expand Up @@ -408,6 +409,7 @@ def commit_and_push(
)
remote = self.repo.remotes[0]
remote.push([self.repo.head.name], callbacks=self.credentials_callback)
self.updated = True
return oid

def build_tree(
Expand Down
9 changes: 2 additions & 7 deletions softpack_core/schemas/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,6 @@ class Environment:
tags: list[str]
hidden: bool
cachedEnvs: list["Environment"] = field(default_factory=list)
envsUpdates: bool = True

requested: Optional[datetime.datetime] = None
build_start: Optional[datetime.datetime] = None
Expand All @@ -337,7 +336,7 @@ def iter(cls) -> list["Environment"]:
Returns:
Iterable[Environment]: An iterator of Environment objects.
"""
if not cls.envsUpdates:
if not artifacts.updated:
return cls.cachedEnvs

statuses = BuildStatus.get_all()
Expand Down Expand Up @@ -372,7 +371,7 @@ def iter(cls) -> list["Environment"]:
env.build_done = status.build_done

cls.cachedEnvs = environment_objects
cls.envsUpdates = False
artifacts.updated = False

return environment_objects

Expand Down Expand Up @@ -549,7 +548,6 @@ def create_new_env(
],
True,
)
cls.envsUpdates = True
artifacts.commit_and_push(tree_oid, "create environment folder")
except RuntimeError as e:
return InvalidInputError(
Expand Down Expand Up @@ -649,7 +647,6 @@ def store_metadata(cls, environment_path: Path, metadata: Box) -> None:
metadata.to_yaml(),
overwrite=True,
)
cls.envsUpdates = True
artifacts.commit_and_push(tree_oid, "update metadata")

@classmethod
Expand Down Expand Up @@ -686,7 +683,6 @@ def delete(cls, name: str, path: str) -> DeleteResponse: # type: ignore
"""
if artifacts.get(Path(path), name):
tree_oid = artifacts.delete_environment(name, path)
cls.envsUpdates = True
artifacts.commit_and_push(tree_oid, "delete environment")
return DeleteEnvironmentSuccess(
message="Successfully deleted the environment"
Expand Down Expand Up @@ -856,7 +852,6 @@ async def write_artifacts(
tree_oid = artifacts.create_files(
Path(folder_path), new_files, overwrite=True
)
cls.envsUpdates = True
artifacts.commit_and_push(tree_oid, "write artifact")
return WriteArtifactSuccess(
message="Successfully written artifact(s)",
Expand Down

0 comments on commit ad9bce0

Please sign in to comment.