Spaces:
Sleeping
Sleeping
File size: 1,321 Bytes
c92cbb8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | # worker_app.py
from flask import Flask, request, jsonify
import ray
app = Flask(__name__)
# ====== Yeh apna FIXED head node address hai ======
HEAD_NODE_ADDRESS = "ray://192.168.1.100:10001"
# ====================================================
connected = False # Worker connection status
@app.route('/worker', methods=['POST'])
def connect_worker():
global connected
if connected:
return jsonify({"message": "Already connected to Ray head node."}), 200
try:
ray.init(address=HEAD_NODE_ADDRESS) # Use the fixed head node address
connected = True
return jsonify({"message": f"Worker connected successfully to head node at {HEAD_NODE_ADDRESS}."}), 200
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route('/noworker', methods=['POST'])
def disconnect_worker():
global connected
if not connected:
return jsonify({"message": "Worker is already disconnected."}), 200
try:
ray.shutdown()
connected = False
return jsonify({"message": "Worker disconnected successfully."}), 200
except Exception as e:
return jsonify({"error": str(e)}), 500
@app.route('/')
def home():
return "Worker Flask App Running."
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
|