Exemplo n.º 1
0
    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
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
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})
Exemplo n.º 4
0
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})
Exemplo n.º 5
0
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})
Exemplo n.º 6
0
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})
Exemplo n.º 7
0
            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
Exemplo n.º 8
0
            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
Exemplo n.º 9
0
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})