Example #1
0
def delete(workflow_id: str) -> None:
    """Delete a workflow, its checkpoints, and other information it may have
       persisted to storage. To stop a running workflow, see
       `workflow.cancel()`.

        NOTE: The caller should ensure that the workflow is not currently
        running before deleting it.

    Args:
        workflow_id: The workflow to delete.

    Examples:
        >>> workflow_step = some_job.step()
        >>> output = workflow_step.run_async(workflow_id="some_job")
        >>> workflow.delete(workflow_id="some_job")
        >>> assert [] == workflow.list_all()

    Returns:
        None

    """

    try:
        status = get_status(workflow_id)
        if status == WorkflowStatus.RUNNING:
            raise WorkflowRunningError("DELETE", workflow_id)
    except ValueError:
        raise WorkflowNotFoundError(workflow_id)

    wf_storage = get_workflow_storage(workflow_id)
    wf_storage.delete_workflow()
Example #2
0
    def delete_workflow(self) -> None:
        # TODO (Alex): There's a race condition here if someone tries to
        # start the workflow between these ops.
        found = self._storage.delete_dir("")
        # TODO (Alex): Different file systems seem to have different
        # behavior when deleting a prefix that doesn't exist, so we may
        # need to catch a broader class of exceptions.

        if not found:
            raise WorkflowNotFoundError(self._workflow_id)
Example #3
0
def get_status(workflow_id: str) -> Optional[WorkflowStatus]:
    try:
        workflow_manager = get_management_actor()
        running = ray.get(workflow_manager.is_workflow_running.remote(workflow_id))
    except Exception:
        running = False
    if running:
        return WorkflowStatus.RUNNING
    store = workflow_storage.get_workflow_storage(workflow_id)
    meta = store.load_workflow_meta()
    if meta is None:
        raise WorkflowNotFoundError(workflow_id)
    if meta.status == WorkflowStatus.RUNNING:
        return WorkflowStatus.RESUMABLE
    return meta.status
Example #4
0
    def delete_workflow(self):
        prefix = self._storage.make_key(self._workflow_id)

        scan = []
        scan_future = self._storage.scan_prefix(prefix)
        delete_future = self._storage.delete_prefix(prefix)

        try:
            # TODO (Alex): There's a race condition here if someone tries to
            # start the workflow between thesea ops.
            scan = asyncio_run(scan_future)
            asyncio_run(delete_future)
        except FileNotFoundError:
            # TODO (Alex): Different file systems seem to have different
            # behavior when deleting a prefix that doesn't exist, so we may
            # need to catch a broader class of exceptions.
            pass

        if not scan:
            raise WorkflowNotFoundError(self._workflow_id)