Skip to content

prefect.server.events.jinja_filters

ui_resource_events_url(ctx, obj)

Given a Resource or Model, return a UI link to the events page filtered for that resource. If an unsupported object is provided, return None.

Currently supports Automation, Resource, Deployment, Flow, FlowRun, TaskRun, and WorkQueue objects. Within a Resource, deployment, flow, flow-run, task-run, and work-queue are supported.

Source code in src/prefect/server/events/jinja_filters.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
@pass_context
def ui_resource_events_url(ctx: Mapping[str, Any], obj: Any) -> Optional[str]:
    """Given a Resource or Model, return a UI link to the events page
    filtered for that resource. If an unsupported object is provided,
    return `None`.

    Currently supports Automation, Resource, Deployment, Flow, FlowRun, TaskRun, and
    WorkQueue objects. Within a Resource, deployment, flow, flow-run, task-run,
    and work-queue are supported."""
    from prefect.server.events.schemas.automations import Automation
    from prefect.server.events.schemas.events import Resource

    url = None
    url_format = "events?resource={resource_id}"

    if isinstance(obj, Automation):
        url = url_format.format(resource_id=f"prefect.automation.{obj.id}")
    elif isinstance(obj, Resource):
        kind, _, id = obj.id.rpartition(".")
        url = url_format.format(resource_id=f"{kind}.{id}")
    elif isinstance(obj, ORMBaseModel):
        kind = model_to_kind.get(type(obj))  # type: ignore

        if kind:
            url = url_format.format(resource_id=f"{kind}.{obj.id}")
    if url:
        return urllib.parse.urljoin(PREFECT_UI_URL.value(), url)
    else:
        return None

ui_url(ctx, obj)

Return the UI URL for the given object.

Source code in src/prefect/server/events/jinja_filters.py
30
31
32
33
@pass_context
def ui_url(ctx: Mapping[str, Any], obj: Any) -> Optional[str]:
    """Return the UI URL for the given object."""
    return url_for(obj, url_type="ui")