def _create_job(self, job_id, data): query = Job.query.options(load_only('id', 'job_id')) query = query.filter_by(job_id=job_id, run=self.run) if query.first(): error('/errors/invalid/', "job with job_id %s already exists" % job_id) else: log.info("Creating job: %s/%s", data.get('name', '<no name!>'), job_id) self.job = Job(data, self.run) Session.commit() return self.job
def index_post(self): """ We update a job here, it should obviously exist already but most likely the data is empty. """ if not self.job: error('/errors/not_found/', 'attempted to update a non-existent job') old_job_status = self.job.status self.job.update(request.json) Session.commit() if self.job.status != old_job_status: log.info("Job %s/%s status changed from %s to %s", self.job.name, self.job.job_id, old_job_status, self.job.status) return dict()