Beispiel #1
0
async def flush_to_db(ctx):
    redis = await create_pool(RedisSettings.from_url(REDIS_URL))
    while 1:
        post_id = await redis.spop(RK_VISITED_POST_IDS)
        if post_id is None:
            break

        post = await Post.get(Q(id=post_id))
        if post:
            post._pageview = int(await redis.get(RK_PAGEVIEW.format(post_id))
                                 or 0)
            await post.save()
Beispiel #2
0
async def flush_to_db(ctx):
    redis = await create_pool(RedisSettings.from_url(REDIS_URL))
    while 1:
        if (post_id := await redis.spop(RK_VISITED_POST_IDS)) is None:
            break

        post = await Post.get(Q(id=post_id))
        if post:
            post._pageview = int(
                await redis.hget(RK_PAGEVIEW.format(post_id), PAGEVIEW_FIELD)
                or 0)
            await post.save()
            print(f'Flush Post(id={post_id}) pageview')
Beispiel #3
0
async def flush_to_db(ctx):
    redis = await create_pool(RedisSettings.from_url(REDIS_URL))
    while 1:
        if (post_id := await redis.spop(RK_VISITED_POST_IDS)) is None:
            break

        post = await Post.filter(id=post_id).first()
        if post:
            post._pageview = int(await redis.hget(
                RK_PAGEVIEW.format(post_id), PAGEVIEW_FIELD) or 0)
            await post.save()
            logger.info(f'Flush Post(id={post_id}) pageview')
        else:
            logger.warning(f'Post(id={post_id}) have deleted!')
Beispiel #4
0
class WorkerSettings:
    functions = [mention_users]
    redis_settings = RedisSettings.from_url(REDIS_URL)
    cron_jobs = [cron(flush_to_db, hour=None)]