← Lesson
Jobs, Not Requests
Joeven
Run
Reset
Python loads on first run
def gateway(message, jobs, queue, now, http_deadline): # Request clock: if we cannot enqueue before the deadline, fail closed. if now >= http_deadline: return {"ok": False, "why": "timeout_before_enqueue"} job_id = "job_" + str(len(jobs) + 1) jobs[job_id] = {"goal": message, "status": "queued", "events": []} queue.append(job_id) return {"ok": True, "job_id": job_id} def poll(job_id, jobs): job = jobs[job_id] return {"status": job["status"], "events": list(job["events"]), "final": job.get("final")} def worker_slice(job_id, jobs, event): job = jobs[job_id] job["status"] = "running" job["events"].append(event) if event.get("final"): job["status"] = "succeeded" job["final"] = event["final"] jobs, queue = {}, [] print("ACK", gateway("refund window?", jobs, queue, now=0, http_deadline=2)) print("POLL empty", poll("job_1", jobs)) worker_slice("job_1", jobs, {"kind": "tool", "name": "search_kb"}) worker_slice("job_1", jobs, {"kind": "final", "final": "5-7 days"}) print("POLL done", poll("job_1", jobs)["status"], poll("job_1", jobs)["final"]) print("HTTP never ran the loop")
Run to execute this in your browser. Nothing is sent to a server.