Example #1
0
 async def _list_workflow(self) -> List[Tuple[str, WorkflowStatus]]:
     workflow_ids = await self._storage.list_workflow()
     metadata = await asyncio.gather(*[
         self._storage.load_workflow_meta(workflow_id)
         for workflow_id in workflow_ids
     ])
     return [(wid, WorkflowStatus(meta["status"]) if meta else None)
             for (wid, meta) in zip(workflow_ids, metadata)]
Example #2
0
 async def _list_workflow(self) -> List[Tuple[str, WorkflowStatus]]:
     prefix = self._storage.make_key("")
     workflow_ids = await self._storage.scan_prefix(prefix)
     metadata = await asyncio.gather(*[
         self._get([workflow_id, WORKFLOW_META], True)
         for workflow_id in workflow_ids
     ])
     return [(wid, WorkflowStatus(meta["status"]) if meta else None)
             for (wid, meta) in zip(workflow_ids, metadata)]
Example #3
0
def list_all(
    status_filter: Optional[Union[Union[WorkflowStatus, str],
                                  Set[Union[WorkflowStatus, str]]]] = None
) -> List[Tuple[str, WorkflowStatus]]:
    """List all workflows matching a given status filter.

    Args:
        status: If given, only returns workflow with that status. This can
            be a single status or set of statuses. The string form of the
            status is also acceptable, i.e.,
            "RUNNING"/"FAILED"/"SUCCESSFUL"/"CANCELED"/"RESUMABLE".

    Examples:
        >>> workflow_step = long_running_job.step()
        >>> wf = workflow_step.run_async(workflow_id="long_running_job")
        >>> jobs = workflow.list_all()
        >>> assert jobs == [ ("long_running_job", workflow.RUNNING) ]
        >>> ray.get(wf)
        >>> jobs = workflow.list_all({workflow.RUNNING})
        >>> assert jobs == []
        >>> jobs = workflow.list_all(workflow.SUCCESSFUL)
        >>> assert jobs == [ ("long_running_job", workflow.SUCCESSFUL) ]

    Returns:
        A list of tuple with workflow id and workflow status
    """
    ensure_ray_initialized()
    if isinstance(status_filter, str):
        status_filter = set({WorkflowStatus(status_filter)})
    elif isinstance(status_filter, WorkflowStatus):
        status_filter = set({status_filter})
    elif isinstance(status_filter, set):
        if all([isinstance(s, str) for s in status_filter]):
            status_filter = {WorkflowStatus(s) for s in status_filter}
        elif not all([isinstance(s, WorkflowStatus) for s in status_filter]):
            raise TypeError("status_filter contains element which is not"
                            " a type of `WorkflowStatus or str`."
                            f" {status_filter}")
    elif status_filter is None:
        status_filter = set(WorkflowStatus.__members__.keys())
    else:
        raise TypeError(
            "status_filter must be WorkflowStatus or a set of WorkflowStatus.")
    return execution.list_all(status_filter)
Example #4
0
    def load_workflow_meta(self) -> Optional[WorkflowMetaData]:
        """Load the metadata of the current workflow.

        Returns:
            The metadata of the current workflow. If it doesn't exist,
            return None.
        """

        try:
            metadata = asyncio_run(
                self._get(self._key_workflow_metadata(), True))
            return WorkflowMetaData(status=WorkflowStatus(metadata["status"]))
        except KeyNotFoundError:
            return None
Example #5
0
 def load_workflow_meta(self) -> Optional[WorkflowMetaData]:
     metadata = asyncio_run(
         self._storage.load_workflow_meta(self._workflow_id))
     if metadata is None:
         return None
     return WorkflowMetaData(status=WorkflowStatus(metadata["status"]))