diff --git a/photoapp/api.py b/photoapp/api.py index fd456b1..46a77ee 100644 --- a/photoapp/api.py +++ b/photoapp/api.py @@ -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): """ diff --git a/photoapp/jobs.py b/photoapp/jobs.py index 46a3b4a..6b1269c 100644 --- a/photoapp/jobs.py +++ b/photoapp/jobs.py @@ -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) +