Skip to content

Commit

Permalink
Merge pull request #451 from ynput/390-exclude-demotest-projects-from…
Browse files Browse the repository at this point in the history
…-metrics

Exclude demo and testing projects from metrics
  • Loading branch information
martastain authored Jan 3, 2025
2 parents 4342413 + 30d48be commit b3eb838
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
7 changes: 6 additions & 1 deletion ayon_server/helpers/deploy_project.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ async def create_project_from_anatomy(
*,
library: bool = False,
user_name: str | None = None,
data: dict[str, Any] | None = None,
) -> None:
"""Deploy a project.
Expand All @@ -145,12 +146,16 @@ async def create_project_from_anatomy(
This is a preffered way of creating a new project, as it will
create all the necessary data in the database.
"""

project_data = anatomy_to_project_data(anatomy)
project_data["data"].update(data or {})

project = ProjectEntity(
payload={
"name": name,
"code": code,
"library": library,
**anatomy_to_project_data(anatomy),
**project_data,
},
)

Expand Down
12 changes: 11 additions & 1 deletion ayon_server/helpers/project_list.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,19 @@ class ProjectListItem(OPModel):
active: bool = True
created_at: datetime
nickname: str
role: str | None = None


async def build_project_list() -> list[ProjectListItem]:
q = """SELECT name, code, active, created_at FROM projects ORDER BY name ASC"""
q = """
SELECT
name,
code,
active,
created_at,
data->>'projectRole' as role
FROM projects ORDER BY name ASC
"""
result: list[dict[str, Any]] = []
try:
async for row in Postgres.iterate(q):
Expand All @@ -28,6 +37,7 @@ async def build_project_list() -> list[ProjectListItem]:
"active": row["active"],
"created_at": row["created_at"],
"nickname": get_nickname(str(row["created_at"]) + row["name"], 2),
"role": row["role"],
}
)
except Postgres.UndefinedTableError:
Expand Down
2 changes: 2 additions & 0 deletions ayon_server/metrics/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,8 @@ async def get_projects(
for project_item in projects:
if not project_item.active:
continue
if project_item.role in ["demo", "test"]:
continue
project = await ProjectEntity.load(project_item.name)
metrics = await get_project_metrics(
project=project,
Expand Down
2 changes: 2 additions & 0 deletions demogen/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ async def main() -> None:
except Exception:
log_traceback()
critical_error("Invalid project data provided")
raise # unreachable, but we need to satisfy mypy

anatomy = Anatomy()
anatomy.tags = generate_tags()
Expand All @@ -91,6 +92,7 @@ async def main() -> None:
name=project_template["name"],
code=project_template["code"],
anatomy=anatomy,
data={"projectRole": "demo"},
)

demo = DemoGen()
Expand Down

0 comments on commit b3eb838

Please sign in to comment.