Skip to content

Commit 95acbfa

Browse files
this needs to move to huey since it sudo
1 parent a76086f commit 95acbfa

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

pioreactorui/tasks.py

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,9 @@ def post_worker(worker: str, endpoint: str, json: dict | None = None) -> tuple[s
292292
r.raise_for_status()
293293
return worker, r.json()
294294
except HTTPErrorStatus as e:
295-
logger.error(f"Could not post to {worker}'s {endpoint=}, sent {json=} and returned {e}. Check connection?")
295+
logger.error(
296+
f"Could not post to {worker}'s {endpoint=}, sent {json=} and returned {e}. Check connection?"
297+
)
296298
return worker, None
297299

298300

@@ -317,7 +319,9 @@ def get_worker(
317319
r.raise_for_status()
318320
return worker, r.json()
319321
except HTTPErrorStatus as e:
320-
logger.error(f"Could not get from {worker}'s {endpoint=}, sent {json=} and returned {e}. Check connection?")
322+
logger.error(
323+
f"Could not get from {worker}'s {endpoint=}, sent {json=} and returned {e}. Check connection?"
324+
)
321325
return worker, None
322326

323327

@@ -340,7 +344,9 @@ def patch_worker(worker: str, endpoint: str, json: dict | None = None) -> tuple[
340344
r.raise_for_status()
341345
return worker, r.json()
342346
except HTTPErrorStatus as e:
343-
logger.error(f"Could not PATCH to {worker}'s {endpoint=}, sent {json=} and returned {e}. Check connection?")
347+
logger.error(
348+
f"Could not PATCH to {worker}'s {endpoint=}, sent {json=} and returned {e}. Check connection?"
349+
)
344350
return worker, None
345351

346352

@@ -363,7 +369,9 @@ def delete_worker(worker: str, endpoint: str, json: dict | None = None) -> tuple
363369
r.raise_for_status()
364370
return worker, r.json() if r.content else None
365371
except HTTPErrorStatus as e:
366-
logger.error(f"Could not DELETE {worker}'s {endpoint=}, sent {json=} and returned {e}. Check connection?")
372+
logger.error(
373+
f"Could not DELETE {worker}'s {endpoint=}, sent {json=} and returned {e}. Check connection?"
374+
)
367375
return worker, None
368376

369377

@@ -377,3 +385,17 @@ def multicast_delete_across_cluster(
377385
tasks = delete_worker.map(((worker, endpoint, json) for worker in workers))
378386

379387
return {worker: response for (worker, response) in tasks.get(blocking=True)}
388+
389+
390+
@huey.task()
391+
def update_clock(new_time: str) -> bool:
392+
# iso8601 format
393+
r = run(["sudo", "date", "-s", new_time])
394+
return r.returncode == 0
395+
396+
397+
@huey.task()
398+
def sync_clock() -> bool:
399+
# iso8601 format
400+
r = run(["sudo", "chronyc", "-a", "makestep"])
401+
return r.returncode == 0

pioreactorui/unit_api.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,12 @@ def set_clock_time():
165165
)
166166

167167
# Update the system clock (requires admin privileges)
168-
run(["sudo", "date", "-s", new_time], check=True)
169-
return jsonify({"status": "success", "message": "Clock time successfully updated"}), 200
168+
t = tasks.update_clock(new_time)
169+
return create_task_response(t)
170170
else:
171171
# sync using chrony
172-
run(["sudo", "chronyc", "-a", "makestep"], check=True)
173-
return jsonify({"status": "success", "message": "Clock time successfully synced"}), 200
172+
t = tasks.sync_clock()
173+
return create_task_response(t)
174174

175175
except Exception as e:
176176
return jsonify({"status": "error", "message": str(e)}), 500

0 commit comments

Comments
 (0)