Пример #1
0
def rebuild_love_count():
    utc_dt = datetime.datetime.utcnow() - datetime.timedelta(
        days=7)  # rebuild last week and this week
    week_start, _ = utc_week_limits(utc_dt)

    set_toggle_state(LOVE_SENDING_ENABLED, False)

    logging.info('Deleting LoveCount table... {}MB'.format(
        memory_usage().current()))
    ndb.delete_multi(
        LoveCount.query(LoveCount.week_start >= week_start).fetch(
            keys_only=True))
    employee_dict = {employee.key: employee for employee in Employee.query()}
    logging.info('Rebuilding LoveCount table... {}MB'.format(
        memory_usage().current()))
    cursor = None
    count = 0
    while True:
        loves, cursor, has_more = Love.query(
            Love.timestamp >= week_start).fetch_page(500, start_cursor=cursor)
        for l in loves:
            LoveCount.update(l, employee_dict=employee_dict)
        count += len(loves)
        logging.info('Processed {} loves, {}MB'.format(
            count,
            memory_usage().current()))
        if not has_more:
            break
    logging.info('Done. {}MB'.format(memory_usage().current()))

    set_toggle_state(LOVE_SENDING_ENABLED, True)
Пример #2
0
def rebuild_love_count():
    set_toggle_state(LOVE_SENDING_ENABLED, False)

    logging.info('Rebuilding LoveCount table...')
    ndb.delete_multi(LoveCount.query().fetch(keys_only=True))
    for l in Love.query().iter(batch_size=1000):
        LoveCount.update(l)
    logging.info('Done.')

    set_toggle_state(LOVE_SENDING_ENABLED, True)
Пример #3
0
def _send_love(recipient_key, message, sender_key, secret):
    """Send love and do associated bookkeeping."""
    new_love = Love(
        sender_key=sender_key,
        recipient_key=recipient_key,
        message=message,
        secret=(secret is True),
    )
    new_love.put()
    LoveCount.update(new_love)

    # Send email asynchronously
    taskqueue.add(url='/tasks/love/email', params={'id': new_love.key.id()})

    if not secret:
        logic.event.add_event(
            logic.event.LOVESENT,
            {'love_id': new_love.key.id()},
        )