def init( *, max_running_workflows: Optional[int] = None, max_pending_workflows: Optional[int] = None, ) -> None: """Initialize workflow. If Ray is not initialized, we will initialize Ray and use ``/tmp/ray/workflow_data`` as the default storage. Args: max_running_workflows: The maximum number of concurrently running workflows. Use -1 as infinity. 'None' means preserving previous setting or initialize the setting with infinity. max_pending_workflows: The maximum number of queued workflows. Use -1 as infinity. 'None' means preserving previous setting or initialize the setting with infinity. """ usage_lib.record_library_usage("workflow") if max_running_workflows is not None: if not isinstance(max_running_workflows, int): raise TypeError( "'max_running_workflows' must be None or an integer.") if max_running_workflows < -1 or max_running_workflows == 0: raise ValueError( "'max_running_workflows' must be a positive integer " "or use -1 as infinity.") if max_pending_workflows is not None: if not isinstance(max_pending_workflows, int): raise TypeError( "'max_pending_workflows' must be None or an integer.") if max_pending_workflows < -1: raise ValueError( "'max_pending_workflows' must be a non-negative integer " "or use -1 as infinity.") if not ray.is_initialized(): # We should use get_temp_dir_path, but for ray client, we don't # have this one. We need a flag to tell whether it's a client # or a driver to use the right dir. # For now, just use /tmp/ray/workflow_data ray.init(storage="file:///tmp/ray/workflow_data") workflow_access.init_management_actor(max_running_workflows, max_pending_workflows) serialization.init_manager()
def init() -> None: """Initialize workflow. If Ray is not initialized, we will initialize Ray and use ``/tmp/ray/workflow_data`` as the default storage. """ usage_lib.record_library_usage("workflow") if not ray.is_initialized(): # We should use get_temp_dir_path, but for ray client, we don't # have this one. We need a flag to tell whether it's a client # or a driver to use the right dir. # For now, just use /tmp/ray/workflow_data ray.init(storage="file:///tmp/ray/workflow_data") workflow_access.init_management_actor() serialization.init_manager() global _is_workflow_initialized _is_workflow_initialized = True
def init(storage: "Optional[Union[str, Storage]]" = None) -> None: """Initialize workflow. Args: storage: The external storage URL or a custom storage class. If not specified, ``/tmp/ray/workflow_data`` will be used. """ if storage is None: storage = os.environ.get("RAY_WORKFLOW_STORAGE") if storage is None: # We should use get_temp_dir_path, but for ray client, we don't # have this one. We need a flag to tell whether it's a client # or a driver to use the right dir. # For now, just use /tmp/ray/workflow_data storage = "file:///tmp/ray/workflow_data" if isinstance(storage, str): logger.info(f"Using storage: {storage}") storage = storage_base.create_storage(storage) elif not isinstance(storage, Storage): raise TypeError("'storage' should be None, str, or Storage type.") try: _storage = storage_base.get_global_storage() except RuntimeError: pass else: # we have to use the 'else' branch because we would raise a # runtime error, but we do not want to be captured by 'except' if _storage.storage_url == storage.storage_url: logger.warning("Calling 'workflow.init()' again with the same " "storage.") else: raise RuntimeError("Calling 'workflow.init()' again with a " "different storage") storage_base.set_global_storage(storage) workflow_access.init_management_actor() serialization.init_manager()