Esempio n. 1
0
async def test_defer_by(arq_redis: ArqRedis):
    j1 = await arq_redis.enqueue_job('foobar', _job_id='job_id', _defer_by=20)
    assert isinstance(j1, Job)
    score = await arq_redis.zscore(default_queue_name, 'job_id')
    ts = timestamp_ms()
    assert score > ts + 19000
    assert ts + 21000 > score
Esempio n. 2
0
async def enquiry(request):
    company = dict(request['company'])

    redis = request.app['redis']
    raw_enquiry_options = await redis.get(REDIS_ENQUIRY_CACHE_KEY %
                                          company['id'])
    ts = timestamp_ms()
    if raw_enquiry_options:
        enquiry_options = json.loads(raw_enquiry_options)
        enquiry_last_updated = enquiry_options['last_updated']
        # 1800 so data should never expire for regularly used forms
        if (ts - enquiry_last_updated) > 1800:
            await request.app['redis'].enqueue_job('update_enquiry_options',
                                                   company)
    else:
        # no enquiry options yet exist, we have to get them now even though it will make the request slow
        ctx = {
            'settings': request.app['settings'],
            'session': request.app['session']
        }
        enquiry_options = await get_enquiry_options(ctx, company=company)
        enquiry_options['last_updated'] = ts
        await store_enquiry_data(redis, company, enquiry_options)

    enq_method = enquiry_post if request.method == METH_POST else enquiry_get
    return await enq_method(request, company, enquiry_options)
Esempio n. 3
0
async def test_defer_by(arq_redis: ArqRedis):
    j1 = await arq_redis.enqueue_job('foobar', _job_id='job_id', _defer_by=20)
    assert isinstance(j1, Job)
    score = await arq_redis.zscore(queue_name, 'job_id')
    ts = timestamp_ms()
    assert score > ts + 19000
    assert ts + 21000 > score
Esempio n. 4
0
async def update_enquiry_options(ctx, company):
    """
    update the redis key containing enquiry option data, including setting the "last_updated" key.
    """
    data = await get_enquiry_options(ctx, company)
    data['last_updated'] = timestamp_ms()
    redis = await create_pool(ctx['settings'].redis_settings)
    await store_enquiry_data(redis, company, data)