job server planning
Gitea/photolib/pipeline/head This commit looks good Details

This commit is contained in:
dave 2023-02-02 22:37:51 -08:00
parent ab2858cb04
commit e649c988cf
1 changed files with 28 additions and 20 deletions

View File

@ -100,6 +100,33 @@ class JobServer(BaseJobServer):
self.engine = dbengine
self.session = create_db_sessionmaker(self.engine)
def handle_notify(self, c, job_uuid):
"""
notify the jobserver that a job needs to be processed. The job may be in any state, including locked. The job
should be processed as follows:
JobStatus.paused: do nothing
JobStatus.done: do nothing
JobStatus.error: do nothing
JobStatus.ready: change to running state and begin processing
JobStatus.running: begin processing.
processing:
- the job is added to a list of "watched" jobs
- we issue a query looking for work
- if no work is found, the job status is changed to Done (or error if any done work has error status?)
"""
raise NotImplementedError()
class ThreadedJobServer(JobServer):
def __init__(self, dbengine):
"""
a version of the jobserver that runs as a thread
"""
super().__init__(dbengine)
self.notifyq = queue.Queue()
self.work_notifyq = queue.Queue()
@cursorwrap
def handle_notify(self, c, job_uuid):
# query the db for the target job, and lock it
@ -133,26 +160,7 @@ class JobServer(BaseJobServer):
for photo_id in photo_ids:
c.add(JobTargetStatus(target_id=target.id, job_id=job.id, photo_id=photo_id))
c.commit() # if this fails, somebody else is handling the job
# query for Photos targeted by the task and allow the job to filter them
# query...
# for each target
# get photo, but also the associated set (and maybe tag)
# filter
# add a JobTargetStatus if the filter allows it
# end our transaction, thus unlocking the job
class ThreadedJobServer(JobServer):
def __init__(self, dbengine):
"""
a version of the jobserver that runs as a thread
"""
super().__init__(dbengine)
self.notifyq = queue.Queue()
self.work_notifyq = queue.Queue()
c.commit() # if this fails, somebody else is handling job
def queue_notify(self, job_uuid):
self.notifyq.put(job_uuid)