Derek
07/03/2024, 2:14 AMMarvin
07/03/2024, 2:15 AMray.ObjectRef from task.submit() using RayTaskRunner. However, we can deduce the approach based on general Prefect and Ray integration principles.
To directly interact with ray.ObjectRef you might consider directly using Ray's API. Here's a speculative approach to achieve this:
1. Create Custom Wrapper Tasks to Return `ObjectRef`:
python
import ray
from prefect import task, flow
from prefect_ray import RayTaskRunner
@task
def example_task(x, y):
return x + y
@task
def submit_task_to_ray(x, y):
# Directly use Ray here
ray.init(address='auto')
obj_ref = ray.remote(example_task.fn).remote(x, y)
return obj_ref
@flow(task_runner=RayTaskRunner())
def my_flow():
# Submit a task to Ray and get the ObjectRef
obj_ref = submit_task_to_ray.submit(1, 2)
print(f"ObjectRef: {obj_ref}")
if __name__ == "__main__":
my_flow()
In this example, the submit_task_to_ray task uses Ray's ray.remote to submit the example_task function directly and returns the ray.ObjectRef.
If you need further assistance or more concrete examples from Prefect or Ray documentation, feel free to notify me. Meanwhile, you can also browse Prefect's examples and guides for more insights: Prefect Examples.