From ca6998e2c5d68893158e51c499ad08f658712253 Mon Sep 17 00:00:00 2001 From: Aleteoryx Date: Mon, 22 Dec 2025 22:29:09 -0500 Subject: [PATCH] seems to be working --- PLAN | 14 ++++++++++---- employer.py | 16 +++++++++++++++- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/PLAN b/PLAN index 527db1c8d50fa8441126ce367012c50fff9fc397..293fdc9eb7364200ded6ef2ab3a43684aee5af58 100644 --- a/PLAN +++ b/PLAN @@ -9,6 +9,9 @@ a job is: server protocol: case-insensitive commands separated by \n on error, send back '?', else send back 'OKAY' + commands which allow [job id] or [for job id] to be omitted + will operate implicitly on the last-mentioned job, or error if + there is none server verbs: - '' @@ -30,11 +33,14 @@ server verbs: - META [FOR JOB id] IS get metadata for id as key: value lines, terminated with a blank line - META key [FOR JOB id] IS value? - set/get id.key - - TAKE JOB id? + set/get id.key. nil is returned as a blank line. + - META key [FOR JOB id] CLEAR + clear a metadata key + + - TAKE [JOB id] mark a job as taken, record timestamp - if n is unset, pick the next available job and send it - back + - TAKE JOB + take the first available job. if none is available, error. - MARK [JOB n] AS marking mark a job as complete, record timestamp - CANCEL [JOB n] diff --git a/employer.py b/employer.py index 55f5829321dfd2406c369fd3234831a35f76753e..9eb689ee0ae534edda6d06448aa83b2fab0c62ad 100644 --- a/employer.py +++ b/employer.py @@ -195,12 +195,26 @@ async def handle_line(topic, tokens, line, reader, writer) -> int: jobs[topic][key] = find_val_in_line(line) case ['meta', key, 'is', *_]: jobs[topic][key] = find_val_in_line(line) + + case ['meta', key, 'for', 'job', int(topic), 'clear']: + del jobs[topic][key] + case ['meta', key, 'clear']: + del jobs[topic][key] case ['take', 'job', int(topic)]: jobs[topic].take() - case ['take', 'job']: + case ['take']: jobs[topic].take() + case ['take', 'job']: + try: + avail = next(jobs['available']) + avail.take() + topic = avail.jid + writer.write(f'{topic}\n'.encode()) + except StopIteration: + raise ValueError('no new jobs') + case ['mark', 'job', int(topic), 'as', str(marking)]: jobs[topic].mark(marking) case ['mark', 'as', str(marking)]: