Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
async def main():
redis = await create_pool(RedisSettings())
for url in ('https://facebook.com', 'https://microsoft.com', 'https://github.com'):
await redis.enqueue_job('download_content', url)
async def main():
redis = await create_pool(RedisSettings())
await redis.enqueue_job('download_content', 'https://httpbin.org/status/503')
async def main():
redis = await create_pool(RedisSettings())
job = await redis.enqueue_job('the_task')
# get the job's id
print(job.job_id)
"""
> 68362958a244465b9be909db4b7b5ab4 (or whatever)
"""
# get information about the job, will include results if the job has finished, but
# doesn't await the job's result
debug(await job.info())
"""
> docs/examples/job_results.py:23 main
JobDef(
function='the_task',
async def main():
redis = await create_pool(RedisSettings())
# deferred by 10 seconds
await redis.enqueue_job('the_task', _defer_by=10)
# deferred by 1 minute
await redis.enqueue_job('the_task', _defer_by=timedelta(minutes=1))
# deferred until jan 28th 2032, you'll be waiting a long time for this...
await redis.enqueue_job('the_task', _defer_until=datetime(2032, 1, 28))
async def async_flush_redis(settings: BaseSettings):
from arq import create_pool
redis = await create_pool(settings.redis_settings)
await redis.flushdb()
redis.close()
await redis.wait_closed()
try:
from .db import prepare_database
from buildpg import asyncpg
except ImportError:
warnings.warn('buildpg and asyncpg need to be installed to use postgres', RuntimeWarning)
else:
await prepare_database(settings, False)
app['pg'] = await asyncpg.create_pool_b(dsn=settings.pg_dsn, min_size=2)
if 'redis' not in app and getattr(settings, 'redis_settings', None):
try:
from arq import create_pool
except ImportError:
warnings.warn('arq and aioredis need to be installed to use redis', RuntimeWarning)
else:
app['redis'] = await create_pool(settings.redis_settings)
if getattr(settings, 'create_http_client', False):
timeout = getattr(settings, 'http_client_timeout', 30)
app['http_client'] = ClientSession(timeout=ClientTimeout(total=timeout))