def require_entity(self, cls): user = self.get_current_user() if not user.is_worker(): abort(failure('Invalid credentials: must be a valid worker')) worker = cls.get_by_id(user.id) if worker is None: abort(failure('Invalid credentials: must be a valid worker')) return worker
def update_job(request, id): job = Job.get_by_id_or_abort(id) worker = request.auth.require_entity(Worker) if job.worker != worker.key.id(): return failure('Worker does not have write access to the job') if 'state' not in request.body: return failure('Updates to jobs must update the state') if request.body['state'] == JobState.QUEUED: return halt_job(request, worker, job) if request.body['state'] == JobState.COMPLETED: return complete_job(request, worker, job) if request.body['state'] == JobState.FAILED: return fail_job(request, worker, job)
def acquire_job(request, id): worker = request.auth.require_entity(Worker) if worker.key.id() != id: return failure("Requested worker not authenticated") if worker.job is not None: return failure('Worker "%s" already owns job' % id) job = dequeue_job() if job is None: return failure("No job available") worker.job = job.key.id() worker.put() return success({"worker": worker, "job": job})
def heartbeat(request, id): worker = request.auth.require_entity(Worker) if worker.key.id() != id: return failure("Requested worker not authenticated") worker.put() return success({"worker": worker})
def acquire_job(request, id): worker = request.auth.require_entity(Worker) if worker.key.id() != id: return failure('Requested worker not authenticated') if worker.job is not None: return failure('Worker "%s" already owns job' % id) job = dequeue_job() if job is None: return failure('No job available') worker.job = job.key.id() worker.put() return success({'worker': worker, 'job': job})
def heartbeat(request, id): worker = request.auth.require_entity(Worker) if worker.key.id() != id: return failure('Requested worker not authenticated') worker.put() return success({'worker': worker})
def wrapped_handler(request, *args, **kwargs): try: request = Request(request) if self.auth_required and request.auth.get_current_user() is None: return failure("Authentication required") return handler(request, *args, **kwargs) except FrameworkAbortError as e: return e.response
def wrapped_handler(request, *args, **kwargs): try: request = Request(request) if self.auth_required and request.auth.get_current_user( ) is None: return failure('Authentication required') return handler(request, *args, **kwargs) except FrameworkAbortError as e: return e.response
def add_job(request): if ('name' not in request.body or 'binary' not in request.body): return failure('Job body incomplete; name and binary fields required') name = request.body['name'] binary = request.body['binary'] params = request.body.get('param', []) id_prehash = str(( ('binary', binary), ('params', tuple(params)) )) m = hashlib.md5() m.update(id_prehash) id = m.hexdigest() job = model.Job(id=id) job.name = name job.binary = binary job.params = params job.put() return success({'job': job})