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
Gitea/photolib/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
d8cac3f641
commit
39a7ba4b02
|
@ -351,7 +351,7 @@ class JobsApiV1(object):
|
||||||
))
|
))
|
||||||
|
|
||||||
# output the job's UUID
|
# 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):
|
def DELETE(self, uuid):
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -9,17 +9,25 @@ class JobSubscriber(object):
|
||||||
"""
|
"""
|
||||||
def __init__(self, client):
|
def __init__(self, client):
|
||||||
self.client = 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):
|
class JobsClient(object):
|
||||||
def __init__(self, dbengine):
|
def __init__(self, dbengine, notifier):
|
||||||
self.engine = dbengine
|
self.engine = dbengine
|
||||||
self.session = create_db_sessionmaker(self.engine)
|
self.session = create_db_sessionmaker(self.engine)
|
||||||
|
self.notifier = notifier
|
||||||
|
|
||||||
@cursorwrap
|
@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(
|
targets: list of dict(
|
||||||
type=JobTargetType.TYPE,
|
type=JobTargetType.TYPE,
|
||||||
targets=[1, 2, 3]
|
targets=[1, 2, 3]
|
||||||
|
@ -39,7 +47,14 @@ class JobsClient(object):
|
||||||
targets=job_targets,
|
targets=job_targets,
|
||||||
)
|
)
|
||||||
|
|
||||||
db.add(j)
|
c.add(j)
|
||||||
db.commit()
|
c.commit()
|
||||||
|
|
||||||
return j.uuid
|
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)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue