mod8-cloudtasks/main.py
def fetch_visits(limit):
    'get most recent visits & add task to delete older visits'
    with ds_client.context():
        data = Visit.query().order(-Visit.timestamp).fetch(limit)
    oldest = time.mktime(data[-1].timestamp.timetuple())
    oldest_str = time.ctime(oldest)
    logging.info('Delete entities older than %s' % oldest_str)
    task = {
        'app_engine_http_request': {
            'relative_uri': '/trim',
            'body': json.dumps({'oldest': oldest}).encode(),
            'headers': {
                'Content-Type': 'application/json',
            },
        }
    }
    ts_client.create_task(parent=QUEUE_PATH, task=task)
    return (v.to_dict() for v in data), oldest_str
get most recent visits & add task to delete older visits
get most recent visits & add task to delete older visits
get most recent visits & add task to delete older visits
def fetch_visits(limit):
    with ds_client.context():
        data = Visit.query().order(-Visit.timestamp).fetch(limit)
    oldest = time.mktime(data[-1].timestamp.timetuple())
    oldest_str = time.ctime(oldest)
    logging.info('Delete entities older than %s' % oldest_str)
    task = {
        'app_engine_http_request': {
            'relative_uri': '/trim',
            'body': json.dumps({'oldest': oldest}).encode(),
            'headers': {
                'Content-Type': 'application/json',
            },
        }
    }
    ts_client.create_task(parent=QUEUE_PATH, task=task)
    return (v.to_dict() for v in data), oldest_str
def fetch_visits ( limit ) : with ds_client . context ( ) : data = Visit . query ( ) . order ( - Visit . timestamp ) . fetch ( limit ) oldest = time . mktime ( data [ - 1 ] . timestamp . timetuple ( ) ) oldest_str = time . ctime ( oldest ) logging . info ( 'Delete entities older than %s' % oldest_str ) task = { 'app_engine_http_request' : { 'relative_uri' : '/trim' , 'body' : json . dumps ( { 'oldest' : oldest } ) . encode ( ) , 'headers' : { 'Content-Type' : 'application/json' , } , } } ts_client . create_task ( parent = QUEUE_PATH , task = task ) return ( v . to_dict ( ) for v in data ) , oldest_str
get most recent visits & add task to delete older visits
get most recent visits & add task to delete older visits
'get most recent visits & add task to delete older visits'
limit