Dispatch explicit jobs to a simulated host
Pass named operations and data arguments through a small, testable remote-job boundary.
Model the boundary, not a remote shell
A remote job needs a target identity, an operation and its arguments. This course's dispatcher runs inside the browser using LabFleet. It does not open SSH or WSMan connections, authenticate to another machine, create an isolated Python interpreter or reproduce remote serialization. Naming the operation explicitly keeps those limits visible.
The teaching contract supports hardware with no arguments and processes with a nonnegative min_rss_mib argument. There is no arbitrary source-code field or eval call. The caller validates every job before dispatch, normalizes IDs and hosts, and rejects duplicate job IDs so results can be correlated unambiguously.
Keep failures attached to their job
An offline host must not erase successful observations from other jobs. Convert ordinary per-job exceptions into an error record with the same job and host IDs. Preserve returned data as structured values for later joins, rather than flattening everything into terminal text.
Pass a fresh arguments dictionary to the dispatcher. An adapter should not unexpectedly mutate the caller's original request. This lesson's allowed arguments are scalar values, so a shallow copy is sufficient. Rich nested parameters would require a separately defined serialization or ownership policy.
Sorting prepared jobs makes output repeatable; it does not create concurrency or execution isolation. Cancellation still propagates. A real transport can later implement this small interface with its own authentication, permissions, timeouts and response validation while the calling code retains its tested correlation and failure policy.
from lab_fleet import LabFleet
print(LabFleet().dispatch("node-a", "processes", {"min_rss_mib":128}))
Put it into practice.
Define run_jobs(dispatch, jobs). Each job has id, host, operation, arguments. Normalize nonempty string id/host with strip/casefold; require unique IDs. Allow hardware with empty arguments dict, or processes with exactly min_rss_mib as a nonnegative integer excluding bool. Validate the whole list before any dispatch, otherwise ValueError. Sort by normalized ID. Call dispatch(host, operation, a copied arguments dict). Return id, host, status="ok", data, error=""; ordinary exceptions return status="error", data=None, error=<class>. Propagate cancellation. Do not alter requests.
See an explained solution
def run_jobs(dispatch, jobs):
prepared=[];seen=set()
for job in jobs:
try:
identifier=job["id"].strip().casefold();host=job["host"].strip().casefold();operation=job["operation"];arguments=job["arguments"]
if not identifier or not host or identifier in seen or operation not in ("hardware","processes") or not isinstance(arguments,dict):raise ValueError("Invalid job")
if operation=="hardware" and arguments:raise ValueError("Hardware takes no arguments")
if operation=="processes" and (set(arguments)!={"min_rss_mib"} or type(arguments["min_rss_mib"]) is not int or arguments["min_rss_mib"]<0):raise ValueError("Invalid process arguments")
except (KeyError,TypeError,AttributeError,ValueError) as error:raise ValueError("Invalid job") from error
seen.add(identifier);prepared.append((identifier,host,operation,dict(arguments)))
rows=[]
for identifier,host,operation,arguments in sorted(prepared):
try:
result=dispatch(host,operation,arguments)
rows.append({"id":identifier,"host":host,"status":"ok","data":result,"error":""})
except Exception as error:
rows.append({"id":identifier,"host":host,"status":"error","data":None,"error":type(error).__name__})
return rows
if __name__ == "__main__":
from lab_fleet import LabFleet
print(run_jobs(LabFleet().dispatch, [{"id":"hardware-a","host":"node-a","operation":"hardware","arguments":{}}]))
Explicit operations and structured results make transport behavior replaceable and failures traceable. The simulation teaches an interface without claiming to implement real remoting.