~aleteoryx/employ

ca6998e2c5d68893158e51c499ad08f658712253 — Aleteoryx 10 days ago 89ef9ea
seems to be working
2 files changed, 25 insertions(+), 5 deletions(-)

M PLAN
M employer.py
M PLAN => PLAN +10 -4
@@ 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]

M employer.py => employer.py +15 -1
@@ 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)]: