use JobSubscriber as the "thick" jobs client and keep JobsClient as low level
Gitea/photolib/pipeline/head There was a failure building this commit Details

This commit is contained in:
dave 2023-01-30 22:03:23 -08:00
parent d8cac3f641
commit 39a7ba4b02
2 changed files with 21 additions and 6 deletions

View File

@ -351,7 +351,7 @@ class JobsApiV1(object):
))
# output the job's UUID
return cherrypy.engine.publish("job-create", body["name"], target_ids)[0]
return cherrypy.engine.publish("create-job", body["name"], target_ids)[0]
def DELETE(self, uuid):
"""

View File

@ -9,17 +9,25 @@ class JobSubscriber(object):
"""
def __init__(self, client):
self.client = client
cherrypy.engine.subscribe("job-create", self.client.create_job) # TODO make "job-create" a const somewhere?
cherrypy.engine.subscribe("create-job", self.create_job) # TODO make "create-job" a const somewhere?
def create_job(self, name, targets):
uuid = self.client.create_job(name, targets)
self.client.notify_server(uuid)
return uuid
class JobsClient(object):
def __init__(self, dbengine):
def __init__(self, dbengine, notifier):
self.engine = dbengine
self.session = create_db_sessionmaker(self.engine)
self.notifier = notifier
@cursorwrap
def create_job(self, db, name, targets):
def create_job(self, c, name, targets):
"""
create a new job in the database
targets: list of dict(
type=JobTargetType.TYPE,
targets=[1, 2, 3]
@ -39,7 +47,14 @@ class JobsClient(object):
targets=job_targets,
)
db.add(j)
db.commit()
c.add(j)
c.commit()
return j.uuid
def notify_server(self, uuid):
"""
notify the job execution server of a job that needs processing because it had been added/updated
"""
self.notifier(uuid)