mirror of
https://github.com/hanzo-ml/kuberay.git
synced 2026-10-30 19:48:47 +00:00
35 lines
795 B
YAML
35 lines
795 B
YAML
apiVersion: v1
|
|
kind: ConfigMap
|
|
metadata:
|
|
name: ray-job-code-sample
|
|
data:
|
|
sample_code.py: |
|
|
import ray
|
|
import os
|
|
import requests
|
|
|
|
ray.init()
|
|
|
|
@ray.remote
|
|
class Counter:
|
|
def __init__(self):
|
|
# Used to verify runtimeEnv
|
|
self.name = os.getenv("counter_name")
|
|
assert self.name == "test_counter"
|
|
self.counter = 0
|
|
|
|
def inc(self):
|
|
self.counter += 1
|
|
|
|
def get_counter(self):
|
|
return "{} got {}".format(self.name, self.counter)
|
|
|
|
counter = Counter.remote()
|
|
|
|
for _ in range(5):
|
|
ray.get(counter.inc.remote())
|
|
print(ray.get(counter.get_counter.remote()))
|
|
|
|
# Verify that the correct runtime env was used for the job.
|
|
assert requests.__version__ == "2.26.0"
|