ttsd-colabcli 1.0.3 → 1.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/core/daemon.py +25 -2
- package/package.json +1 -1
package/core/daemon.py
CHANGED
|
@@ -106,7 +106,19 @@ async def launch_worker(email: str, public_url: str):
|
|
|
106
106
|
|
|
107
107
|
try:
|
|
108
108
|
from app.colab_cli.runtime import ColabRuntime
|
|
109
|
-
|
|
109
|
+
# Try local first (satellite_node/daemon.py), fallback to packaged structure
|
|
110
|
+
possible_paths = [
|
|
111
|
+
os.path.join(os.path.dirname(__file__), "../colab/worker.py"),
|
|
112
|
+
os.path.join(os.path.dirname(__file__), "colab", "worker.py")
|
|
113
|
+
]
|
|
114
|
+
_worker_bytes = None
|
|
115
|
+
for p in possible_paths:
|
|
116
|
+
if os.path.exists(p):
|
|
117
|
+
_worker_bytes = open(p, "rb").read()
|
|
118
|
+
break
|
|
119
|
+
if not _worker_bytes:
|
|
120
|
+
raise FileNotFoundError(f"Could not find worker.py in {possible_paths}")
|
|
121
|
+
|
|
110
122
|
_worker_b64 = base64.b64encode(_worker_bytes).decode()
|
|
111
123
|
|
|
112
124
|
_rt = ColabRuntime(url, token, session_name=name)
|
|
@@ -133,7 +145,18 @@ print("DEPLOYED PID=" + str(proc.pid) + " ALIVE=" + str(ret is None), flush=True
|
|
|
133
145
|
await loop.run_in_executor(None, lambda: _rt.execute_code(_deploy_code, timeout=300))
|
|
134
146
|
logger.info("Worker deployed on Colab runtime for %s", email)
|
|
135
147
|
except Exception as e:
|
|
136
|
-
logger.error("Worker deploy failed: %s", e)
|
|
148
|
+
logger.error("Worker deploy failed: %s, cleaning up Colab assignment", e)
|
|
149
|
+
# Rollback: unassign the runtime so quota isn't wasted
|
|
150
|
+
try:
|
|
151
|
+
from app.colab_cli.common import kill_process
|
|
152
|
+
if pid:
|
|
153
|
+
kill_process(pid)
|
|
154
|
+
except Exception:
|
|
155
|
+
pass
|
|
156
|
+
try:
|
|
157
|
+
await loop.run_in_executor(None, _client.unassign, endpoint)
|
|
158
|
+
except Exception:
|
|
159
|
+
pass
|
|
137
160
|
await report_status(email, "FAILED", error=str(e))
|
|
138
161
|
return
|
|
139
162
|
|