use JobSubscriber as the "thick" jobs client and keep JobsClient as low level
Some checks failed
Gitea/photolib/pipeline/head There was a failure building this commit
Some checks failed
Gitea/photolib/pipeline/head There was a failure building this commit
This commit is contained in:
parent
d8cac3f641
commit
39a7ba4b02
@ -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):
|
||||
"""
|
||||
|
@ -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)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user