<@ULVA73B9P> I am using RayTaskRunner to run tasks...
# marvin-in-the-wild
d
@Marvin I am using RayTaskRunner to run tasks on a remote Ray cluster with task.submit(). How can I get the ray.ObjectRef from the calls to ray.remote that occur in submit()?
m
There doesn't seem to be specific documentation or issues directly addressing obtaining
ray.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`:
Copy code
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.