topless
4/20/2016 - 9:51 AM

Deferred app engine queue, to iterate though all entities.

Deferred app engine queue, to iterate though all entities.

@api_v1.resource('/run/patch', endpoint='api.run.patch')
class PatchRunAPI(restful.Resource):
  def get(self):
    deferred.defer(update_run_task)
    return flask.jsonify({
      'result': 'The queues started patching all run models!!',
      'status': 'success',
    })


def update_run_task(next_cursor=None):
  run_dbs, next_cursor = util.get_dbs(model.Run.query(), cursor=next_cursor)
  if run_dbs:
    for run_db in run_dbs:
      logging.warning(run_db)

  logging.warning("Patched %d entities." % len(run_dbs))
  if next_cursor['next'] is not None:
    deferred.defer(update_run_task, next_cursor['next'])
  return