def run_async(self, workflow_id: Optional[str] = None) -> ObjectRef: """Run a workflow asynchronously. If the workflow with the given id already exists, it will be resumed. Examples: >>> @workflow.step ... def book_flight(origin: str, dest: str) -> Flight: ... return Flight(...) >>> @workflow.step ... def book_hotel(location: str) -> Reservation: ... return Reservation(...) >>> @workflow.step ... def finalize_trip(bookings: List[Any]) -> Trip: ... return Trip(...) >>> flight1 = book_flight.step("OAK", "SAN") >>> flight2 = book_flight.step("SAN", "OAK") >>> hotel = book_hotel.step("SAN") >>> trip = finalize_trip.step([flight1, flight2, hotel]) >>> result = ray.get(trip.run_async()) Args: workflow_id: A unique identifier that can be used to resume the workflow. If not specified, a random id will be generated. """ # TODO(suquark): avoid cyclic importing from ray.workflow.execution import run self._step_id = None return run(self, workflow_id)
def run_async( self, workflow_id: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None, ) -> ObjectRef: """Run a workflow asynchronously. If the workflow with the given id already exists, it will be resumed. Examples: >>> from ray import workflow >>> Flight, Reservation, Trip = ... # doctest: +SKIP >>> @workflow.step # doctest: +SKIP ... def book_flight(origin: str, dest: str) -> Flight: # doctest: +SKIP ... return Flight(...) # doctest: +SKIP >>> @workflow.step # doctest: +SKIP ... def book_hotel(location: str) -> Reservation: # doctest: +SKIP ... return Reservation(...) # doctest: +SKIP >>> @workflow.step # doctest: +SKIP ... def finalize_trip(bookings: List[Any]) -> Trip: # doctest: +SKIP ... return Trip(...) # doctest: +SKIP >>> flight1 = book_flight.step("OAK", "SAN") # doctest: +SKIP >>> flight2 = book_flight.step("SAN", "OAK") # doctest: +SKIP >>> hotel = book_hotel.step("SAN") # doctest: +SKIP >>> trip = finalize_trip.step([flight1, flight2, hotel]) # doctest: +SKIP >>> result = ray.get(trip.run_async()) # doctest: +SKIP Args: workflow_id: A unique identifier that can be used to resume the workflow. If not specified, a random id will be generated. metadata: The metadata to add to the workflow. It has to be able to serialize to json. Returns: The running result as ray.ObjectRef. """ # TODO(suquark): avoid cyclic importing from ray.workflow.execution import run from ray.workflow.api import _ensure_workflow_initialized _ensure_workflow_initialized() self._step_id = None return run(self, workflow_id, metadata)
def run_async(workflow_id: Optional[str] = None, metadata: Optional[Dict[str, Any]] = None): """Run a workflow asynchronously. If the workflow with the given id already exists, it will be resumed. Args: workflow_id: A unique identifier that can be used to resume the workflow. If not specified, a random id will be generated. metadata: The metadata to add to the workflow. It has to be able to serialize to json. Returns: The running result as ray.ObjectRef. """ _ensure_workflow_initialized() return execution.run(dag_node, input_data, workflow_id, metadata)