Example #1
0
 def redis_settings(self) -> RedisSettings:
     return RedisSettings(
         host=self.redis_host,
         port=self.redis_port,
         database=self.redis_database,
         password=self.redis_password,
     )
Example #2
0
 def parse_redis_settings(cls, v):
     conf = urlparse(v)
     return RedisSettings(
         host=conf.hostname,
         port=conf.port,
         password=conf.password,
         database=int((conf.path or '0').strip('/')),
     )
Example #3
0
async def test_redis_success_log(loop, caplog):
    settings = RedisSettings()
    pool = await create_pool_lenient(settings, loop)
    assert 'redis connection successful' not in caplog
    pool.close()
    await pool.wait_closed()

    pool = await create_pool_lenient(settings, loop, _retry=1)
    assert 'redis connection successful' not in caplog
    pool.close()
    await pool.wait_closed()
Example #4
0
async def test_redis_timeout(loop, mocker):
    mocker.spy(arq.utils.asyncio, 'sleep')
    r = RedisMixin(redis_settings=RedisSettings(port=0, conn_retry_delay=0), loop=loop)
    with pytest.raises(OSError):
        await r.get_redis()
    assert arq.utils.asyncio.sleep.call_count == 5
Example #5
0
def test_settings_changed():
    settings = RedisSettings(port=123)
    assert settings.port == 123
    assert ('<RedisSettings host=localhost port=123 database=0 password=None conn_retries=5 '
            'conn_timeout=1 conn_retry_delay=1>') == str(settings)
Example #6
0
def test_settings_changed():
    settings = RedisSettings(port=123)
    assert settings.port == 123
Example #7
0
File: app.py Project: stegben/arq
async def start_job(request):
    data = await request.post()
    session = await get_session(request)
    try:
        url = data['url']
        count = int(data['count'])
    except (KeyError, ValueError) as e:
        session['message'] = f'Invalid input, {e.__class__.__name__}: {e}'
    else:
        await request.app['downloader'].download_content(url, count)
        session['message'] = f'Downloading "{url}" ' + (f'{count} times.' if
                                                        count > 1 else 'once.')
    raise web.HTTPFound(location='/')


redis_settings = RedisSettings(host=os.getenv('REDIS_HOST', 'localhost'))


async def shutdown(app):
    await app['downloader'].close()


def create_app():
    app = web.Application()
    app.router.add_get('/', index)
    app.router.add_post('/start-job/', start_job)
    app['downloader'] = Downloader(redis_settings=redis_settings)
    app.on_shutdown.append(shutdown)
    session_setup(app, SimpleCookieStorage())
    return app