Skip to content

update worker metadata #17584

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

Closed
wants to merge 2 commits into from
Closed
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
21 changes: 14 additions & 7 deletions scripts/validate_collection_view_content.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
# /// script
# dependencies = ["fastjsonschema"]
# ///

import json
from pathlib import Path
from typing import Literal
from typing import Any, Literal

import fastjsonschema

EXCLUDE_TYPES = {"demo-flow"}

CollectionViewVariety = Literal["flow", "worker", "block"]

flow_schema = {
flow_schema: dict[str, Any] = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
Expand Down Expand Up @@ -37,7 +41,7 @@
],
}

worker_schema = {
worker_schema: dict[str, Any] = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
Expand All @@ -58,7 +62,7 @@
],
}

block_schema = {
block_schema: dict[str, Any] = {
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
Expand Down Expand Up @@ -111,7 +115,9 @@
}


def validate_view_content(view_dict: dict, variety: CollectionViewVariety) -> None:
def validate_view_content(
view_dict: dict[str, Any], variety: CollectionViewVariety
) -> None:
"""Raises an error if the view content is not valid."""

if variety == "flow":
Expand All @@ -123,14 +129,14 @@ def validate_view_content(view_dict: dict, variety: CollectionViewVariety) -> No
else:
raise ValueError(f"Invalid variety: {variety}")

validate = fastjsonschema.compile(schema)
validate = fastjsonschema.compile(schema) # type: ignore

for collection_name, collection_metadata in view_dict.items():
if variety == "block":
collection_metadata = collection_metadata["block_types"]
try:
# raise validation errors if any metadata doesn't match the schema
list(map(validate, collection_metadata.values()))
list(map(validate, collection_metadata.values())) # type: ignore
except IndexError: # to catch something like {"prefect-X": {}}
raise ValueError("There's a key with empty value in this view!")
print(f" Validated {collection_name} summary in {variety} view!")
Expand All @@ -146,6 +152,7 @@ def validate_view_content(view_dict: dict, variety: CollectionViewVariety) -> No

for variety, file in included_paths:
path = Path(file)

if any(exclude in path.name for exclude in EXCLUDE_TYPES):
continue

Expand Down
Loading