-
Notifications
You must be signed in to change notification settings - Fork 14
/
environment.py
22 lines (18 loc) · 831 Bytes
/
environment.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import asyncio
from prefect.cli.cloud import get_current_workspace
from prefect.client.cloud import get_cloud_client, CloudUnauthorizedError
async def get_workspace() -> str:
try:
async with get_cloud_client() as client:
workspaces = await client.read_workspaces()
current_workspace = get_current_workspace(workspaces)
workspace_handle = current_workspace.split("/")[-1]
return workspace_handle
except CloudUnauthorizedError:
return "default" # means: local Orion instance and the default CLI Profile
def get_env() -> str:
"""
This could be replaced by some other logic to return whether you run sth in dev vs. prod
:return: string representing the environment, same as assigned to block names
"""
return asyncio.run(get_workspace())