Spaces:
Sleeping
Sleeping
| # 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 | |
| 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 | |
| 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 | |
| def home(): | |
| return "Worker Flask App Running." | |
| if __name__ == '__main__': | |
| app.run(host='0.0.0.0', port=5000) | |