-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ray-job-support
- Loading branch information
Showing
14 changed files
with
334 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import argparse | ||
import ray | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('--arg', type=str) | ||
args = parser.parse_args() | ||
|
||
@ray.remote | ||
def f(arg): | ||
return "Argument is '" + arg + "'" | ||
|
||
args = ["This", "is", "a", "test"] + [args.arg] | ||
results = ray.get([f.remote(arg) for arg in args]) | ||
|
||
print("\n".join(results)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import os | ||
import subprocess | ||
import tempfile | ||
import yaml | ||
|
||
import ray | ||
|
||
from prefect import flow, task, get_run_logger | ||
from prefect_ray import RayTaskRunner | ||
|
||
# This custom resource will cause another node to be added | ||
# to the cluster so we can test that the working directory | ||
# is indeed synced to all nodes in the cluster. | ||
@ray.remote(resources={"custom_resource": 1}) | ||
def remote_task(): | ||
from ci.test_python_file import test | ||
return test() | ||
|
||
@task | ||
def test_task(): | ||
return ray.get(remote_task.remote()) | ||
|
||
@task | ||
def anyscale_job(args): | ||
job_config = { | ||
"name": "my-anyscale-job", | ||
"cloud": "anyscale_v2_default_cloud", | ||
"description": "An Anyscale Job submitted from Prefect.", | ||
"cluster_env": "default_cluster_env_2.3.1_py39", | ||
"runtime_env": { | ||
"working_dir": "ci/", | ||
"upload_path": "s3://anyscale-prefect-integration-test/working-dir/", | ||
}, | ||
"entrypoint": "python anyscale_job.py " + " ".join([f"--{key} {val}" for key, val in args.items()]), | ||
} | ||
|
||
with tempfile.NamedTemporaryFile(mode="w") as f: | ||
yaml.dump(job_config, f) | ||
f.flush() | ||
# Submit an Anyscale Job from Prefect and record the logs | ||
output = subprocess.check_output( | ||
["anyscale", "job", "submit", f.name, "--follow"] | ||
) | ||
logger = get_run_logger() | ||
logger.info("Anyscale Job output: " + output.decode()) | ||
|
||
@flow(task_runner=RayTaskRunner) | ||
def complex_flow(): | ||
result = test_task.submit() | ||
assert result.result() == 42 | ||
result = anyscale_job.submit({"arg": "value"}) | ||
assert result.result() == None | ||
|
||
if __name__ == "__main__": | ||
complex_flow() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
name: prefect-agent-awssecrets-28 | ||
cloud: "anyscale_v2_default_cloud" | ||
ray_serve_config: | ||
import_path: start_anyscale_service:entrypoint | ||
runtime_env: | ||
env_vars: | ||
PREFECT_API_URL: $PREFECT_API_URL | ||
ANYSCALE_PREFECT_AWS_SECRET_ID: prefect-api-key | ||
ANYSCALE_PREFECT_AWS_REGION: us-west-2 | ||
ANYSCALE_PREFECT_QUEUE: test-awssecrets | ||
ANYSCALE_PREFECT_DEVELOPMENT: "1" | ||
working_dir: . | ||
upload_path: "s3://anyscale-prefect-integration-test/github-working-dir/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,12 @@ | ||
name: prefect-agent-18 | ||
entrypoint: pip install prefect-anyscale && PREFECT_API_URL=$PREFECT_API_URL PREFECT_API_KEY=$PREFECT_API_KEY python start_anyscale_service.py --queue test | ||
runtime_env: | ||
working_dir: . | ||
upload_path: "s3://anyscale-prefect-integration-test/github-working-dir/" | ||
healthcheck_url: "/healthcheck" | ||
name: prefect-agent-28 | ||
cloud: "anyscale_v2_default_cloud" | ||
ray_serve_config: | ||
import_path: start_anyscale_service:entrypoint | ||
runtime_env: | ||
env_vars: | ||
PREFECT_API_URL: $PREFECT_API_URL | ||
PREFECT_API_KEY: $PREFECT_API_KEY | ||
ANYSCALE_PREFECT_QUEUE: test | ||
ANYSCALE_PREFECT_DEVELOPMENT: "1" | ||
working_dir: . | ||
upload_path: "s3://anyscale-prefect-integration-test/github-working-dir/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
def test(): | ||
return 42 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,12 @@ | ||
name: prefect-agent-10 | ||
entrypoint: pip install prefect-anyscale && PREFECT_API_URL=$PREFECT_API_URL PREFECT_API_KEY=$PREFECT_API_KEY python start_anyscale_service.py --queue test | ||
runtime_env: | ||
working_dir: https://github.com/anyscale/prefect-anyscale/archive/refs/tags/v0.1.0.zip | ||
healthcheck_url: "/healthcheck" | ||
name: prefect-agent | ||
ray_serve_config: | ||
import_path: start_anyscale_service:entrypoint | ||
runtime_env: | ||
env_vars: | ||
PREFECT_API_URL: $PREFECT_API_URL | ||
# Consider using a secret manager to store the PREFECT_API_KEY token | ||
# (see instructions in README.md) | ||
PREFECT_API_KEY: $PREFECT_API_KEY | ||
ANYSCALE_PREFECT_QUEUE: test | ||
pip: ["prefect-anyscale"] | ||
working_dir: https://github.com/anyscale/prefect-anyscale/archive/refs/tags/v0.2.0.zip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,23 @@ | ||
from prefect_anyscale.infrastructure import AnyscaleJob, RayJob | ||
|
||
|
||
def prefect_runtime_environment_hook(runtime_env): | ||
|
||
if not runtime_env: | ||
runtime_env = {} | ||
|
||
# If no working_dir is specified, we use the current | ||
# directory as the working directory -- this will be | ||
# the directory containing the source code which is | ||
# downloaded by the Prefect engine. | ||
if not runtime_env.get("working_dir"): | ||
runtime_env["working_dir"] = "." | ||
|
||
return runtime_env | ||
|
||
|
||
__all__ = [ | ||
"AnyscaleJob", | ||
"RayJob", | ||
"prefect_runtime_environment_hook", | ||
] |
Oops, something went wrong.