Skip to content

Commit

Permalink
Improve RedisSettings explanation in main_demo.py (#422)
Browse files Browse the repository at this point in the history
Co-authored-by: Samuel Colvin <s@muelcolvin.com>
  • Loading branch information
RamonGiovane and samuelcolvin committed Apr 1, 2024
1 parent 9731f54 commit 33e4760
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions docs/examples/main_demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
from arq import create_pool
from arq.connections import RedisSettings

# Here you can configure the Redis connection.
# The default is to connect to localhost:6379, no password.
REDIS_SETTINGS = RedisSettings()

async def download_content(ctx, url):
session: AsyncClient = ctx['session']
response = await session.get(url)
Expand All @@ -16,17 +20,19 @@ async def shutdown(ctx):
await ctx['session'].aclose()

async def main():
redis = await create_pool(RedisSettings())
redis = await create_pool(REDIS_SETTINGS)
for url in ('https://facebook.com', 'https://microsoft.com', 'https://github.com'):
await redis.enqueue_job('download_content', url)

# WorkerSettings defines the settings to use when creating the work,
# it's used by the arq cli.
# For a list of available settings, see https://arq-docs.helpmanual.io/#arq.worker.Worker
# It's used by the arq CLI.
# redis_settings might be ommitted here if using the default settings
# For a list of all available settings, see https://arq-docs.helpmanual.io/#arq.worker.Worker
class WorkerSettings:
functions = [download_content]
on_startup = startup
on_shutdown = shutdown
redis_settings = REDIS_SETTINGS

if __name__ == '__main__':
asyncio.run(main())

0 comments on commit 33e4760

Please sign in to comment.