import asyncio import functools import click from procs import flush_messages from payphone.db import setup, models from payphone.core import logging logging.setup("Tasks") def coroutine(f): @functools.wraps(f) def wrapper(*args, **kwargs): return asyncio.run(f(*args, **kwargs)) return wrapper @click.group() @coroutine async def main(): await setup.init() @main.command() @coroutine async def flush(): """Flush all messages in Redis to the database. Runs every 5 seconds.""" while True: await flush_messages.flush() await asyncio.sleep(5) @main.command() @coroutine async def delete_accounts(): """Delete all accounts that were scheduled for deletion. Runs every 1 hour.""" while True: await models.User.filter(is_deleting=True).delete() await asyncio.sleep(60 * 60) if __name__ == "__main__": main()