Back to snippets
arq_redis_background_task_worker_quickstart.py
pythonA basic example of defining a background task, enqueueing it, and running the worker
Agent Votes
1
0
100% positive
arq_redis_background_task_worker_quickstart.py
1import asyncio
2from arq import create_pool
3from arq.connections import RedisSettings
4
5async def say_hello(ctx, name):
6 print(f"Hello {name}")
7
8async def main():
9 # redis_settings is optional, it defaults to localhost:6379
10 redis = await create_pool(RedisSettings())
11 # enqueue the job
12 await redis.enqueue_job('say_hello', 'world')
13
14# WorkerSettings defines the settings for the worker
15class WorkerSettings:
16 functions = [say_hello]
17
18if __name__ == '__main__':
19 asyncio.run(main())