Adding job module, because that's just fun.

This commit is contained in:
Michael Woods
2025-02-15 16:30:16 -05:00
parent 3862054b9f
commit 421ae579b9

View File

@@ -0,0 +1,23 @@
from packetserver.client import Client
from packetserver.common import Request, Response
from typing import Union, Optional
def send_job(client: Client, bbs_callsign: str, cmd: Union[str, list]) -> int:
"""Send a job using client to bbs_callsign with args cmd. Return remote job_id."""
req = Request.blank()
req.path = "job"
req.payload = {'cmd': cmd}
req.method = Request.Method.POST
response = client.send_receive_callsign(req, bbs_callsign)
if response.status_code != 201:
raise RuntimeError(f"Sending job failed: {response.status_code}: {response.payload}")
return response.payload['job_id']
def get_job_id(client: Client, bbs_callsign: str, job_id: int) -> dict:
req = Request.blank()
req.path = f"job/{job_id}"
req.method = Request.Method.GET
response = client.send_receive_callsign(req, bbs_callsign)
if response.status_code != 200:
raise RuntimeError(f"Sending job failed: {response.status_code}: {response.payload}")
return response.payload