mod8-cloudtasks/main.py
def trim():
    '(push) task queue handler to delete oldest visits'
    oldest = float(request.get_json().get('oldest'))
    with ds_client.context():
        keys = Visit.query(
                Visit.timestamp < datetime.fromtimestamp(oldest)
        ).fetch(keys_only=True)
        nkeys = len(keys)
        if nkeys:
            logging.info('Deleting %d entities: %s' % (
                    nkeys, ', '.join(str(k.id()) for k in keys)))
            ndb.delete_multi(keys)
        else:
            logging.info(
                    'No entities older than: %s' % time.ctime(oldest))
    return ''
(push) task queue handler to delete oldest visits
(push) task queue handler to delete oldest visits
( push ) task queue handler to delete oldest visits
def trim():
    oldest = float(request.get_json().get('oldest'))
    with ds_client.context():
        keys = Visit.query(
                Visit.timestamp < datetime.fromtimestamp(oldest)
        ).fetch(keys_only=True)
        nkeys = len(keys)
        if nkeys:
            logging.info('Deleting %d entities: %s' % (
                    nkeys, ', '.join(str(k.id()) for k in keys)))
            ndb.delete_multi(keys)
        else:
            logging.info(
                    'No entities older than: %s' % time.ctime(oldest))
    return ''
def trim ( ) : oldest = float ( request . get_json ( ) . get ( 'oldest' ) ) with ds_client . context ( ) : keys = Visit . query ( Visit . timestamp < datetime . fromtimestamp ( oldest ) ) . fetch ( keys_only = True ) nkeys = len ( keys ) if nkeys : logging . info ( 'Deleting %d entities: %s' % ( nkeys , ', ' . join ( str ( k . id ( ) ) for k in keys ) ) ) ndb . delete_multi ( keys ) else : logging . info ( 'No entities older than: %s' % time . ctime ( oldest ) ) return ''
(push) task queue handler to delete oldest visits
( push ) task queue handler to delete oldest visits
'(push) task queue handler to delete oldest visits'