def create_link(link: str) -> Optional[str]: """ Create a link artifact Args: - link (str): the link to post Returns: - str: the task run artifact ID """ if not _running_with_backend(): return None client = Client() return client.create_task_run_artifact( task_run_id=context.get("task_run_id"), kind="link", data={"link": link})
def create_markdown(markdown: str) -> Optional[str]: """ Create a markdown artifact Args: - markdown (str): the markdown to post Returns: - str: the task run artifact ID """ if not _running_with_backend(): return None client = Client() return client.create_task_run_artifact( task_run_id=context.get("task_run_id"), kind="markdown", data={"markdown": markdown}, )
def _create_task_run_artifact(kind: str, data: dict) -> str: client = Client() task_run_id = context.get("task_run_id") # XXX: there's a race condition in the cloud backend for mapped tasks where # the task run lookup might fail temporarily. This should last a few # seconds max, for now we retry a few times. retries = 5 while True: try: return client.create_task_run_artifact(task_run_id=task_run_id, kind=kind, data=data) except ClientError as exc: # If it's a not found error and we still have retries left, retry if "not found" in str(exc).lower() and retries: time.sleep(1) retries -= 1 continue raise
def create_link(link: str) -> Optional[str]: """ Create a link artifact Note: The functionality here is experimental, and may change between versions without notice. Use at your own risk. Args: - link (str): the link to post Returns: - str: the task run artifact ID """ if not _running_with_backend(): return None client = Client() return client.create_task_run_artifact( task_run_id=context.get("task_run_id"), kind="link", data={"link": link})