job server planning
Gitea/photolib/pipeline/head This commit looks good
Details
Gitea/photolib/pipeline/head This commit looks good
Details
This commit is contained in:
parent
ab2858cb04
commit
e649c988cf
|
@ -100,6 +100,33 @@ class JobServer(BaseJobServer):
|
||||||
self.engine = dbengine
|
self.engine = dbengine
|
||||||
self.session = create_db_sessionmaker(self.engine)
|
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
|
@cursorwrap
|
||||||
def handle_notify(self, c, job_uuid):
|
def handle_notify(self, c, job_uuid):
|
||||||
# query the db for the target job, and lock it
|
# query the db for the target job, and lock it
|
||||||
|
@ -133,26 +160,7 @@ class JobServer(BaseJobServer):
|
||||||
for photo_id in photo_ids:
|
for photo_id in photo_ids:
|
||||||
c.add(JobTargetStatus(target_id=target.id, job_id=job.id, photo_id=photo_id))
|
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
|
c.commit() # if this fails, somebody else is handling 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()
|
|
||||||
|
|
||||||
def queue_notify(self, job_uuid):
|
def queue_notify(self, job_uuid):
|
||||||
self.notifyq.put(job_uuid)
|
self.notifyq.put(job_uuid)
|
||||||
|
|
Loading…
Reference in New Issue