Skip to content

Commit

Permalink
Put agent file at a predictable location and pass cluster environment (
Browse files Browse the repository at this point in the history
…#2)

* Put agent file at the right location

* add additional args

* add logging

* update

* update

* update

* update

* fix
  • Loading branch information
pcmoritz authored Nov 8, 2022
1 parent f427e32 commit 764662b
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
18 changes: 17 additions & 1 deletion anyscale_prefect_agent.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
"""
Version 0.0.1 of the Anyscale Prefect Agent.
Version 0.0.2 of the Anyscale Prefect Agent.
"""

import argparse
import logging
import os
import subprocess
import tempfile

logging.basicConfig(level=logging.INFO)

parser = argparse.ArgumentParser(add_help=False)
parser.add_argument("--cluster-env", type=str)
parser.add_argument("--compute-config", type=str)
args = parser.parse_args()

api_url = os.environ.get("PREFECT_API_URL")
api_key = os.environ.get("PREFECT_API_KEY")
flow_run_id = os.environ.get("PREFECT__FLOW_RUN_ID")
Expand All @@ -24,7 +33,14 @@
entrypoint: "{}"
""".format(cmd)

if args.compute_config:
content += 'compute_config: "{}"\n'.format(args.compute_config)

if args.cluster_env:
content += 'cluster_env: "{}"\n'.format(args.cluster_env)

with tempfile.NamedTemporaryFile(mode="w") as f:
f.write(content)
f.flush()
logging.info(f"Submitting Anyscale Job with configuration '{content}'")
subprocess.check_call(["anyscale", "job", "submit", f.name])
6 changes: 6 additions & 0 deletions start_anyscale_service.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
import os
import ray
import shutil
import subprocess

ray.init()

ANYSCALE_PREFECT_DIR = os.path.dirname(os.path.realpath(__file__))

shutil.copy(os.path.join(ANYSCALE_PREFECT_DIR, "anyscale_prefect_agent.py"), "/home/ray/")

subprocess.check_call(["prefect", "agent", "start", "-q", "test"])

0 comments on commit 764662b

Please sign in to comment.