Ejemplo n.º 1
0
class WorkerSettings:
    functions = [
        set_cached_members,
        get_characters,
        process_activity,
        store_member_history,
        store_all_games,
        func(save_last_active, keep_result=240),
        func(store_last_active, keep_result=240),
    ]
    on_startup = startup
    on_shutdown = shutdown
    redis_settings = config.arq_redis
    max_jobs = ARQ_MAX_JOBS
    job_timeout = ARQ_JOB_TIMEOUT

    def job_serializer(b):
        return serializer(b)

    def job_deserializer(b):
        return deserializer(b)
Ejemplo n.º 2
0
async def test_enqueue_job(arq_redis: ArqRedis,
                           worker,
                           queue_name=default_queue_name):
    async def foobar(ctx, *args, **kwargs):
        return 42

    j = await arq_redis.enqueue_job('foobar',
                                    1,
                                    2,
                                    c=3,
                                    _queue_name=queue_name)
    assert isinstance(j, Job)
    assert JobStatus.queued == await j.status()
    worker: Worker = worker(functions=[func(foobar, name='foobar')],
                            queue_name=queue_name)
    await worker.main()
    r = await j.result(poll_delay=0)
    assert r == 42
    assert JobStatus.complete == await j.status()
    info = await j.info()
    expected_queue_name = queue_name or arq_redis.default_queue_name
    assert info == JobResult(
        job_try=1,
        function='foobar',
        args=(1, 2),
        kwargs={'c': 3},
        enqueue_time=IsNow(tz='utc'),
        success=True,
        result=42,
        start_time=IsNow(tz='utc'),
        finish_time=IsNow(tz='utc'),
        score=None,
        queue_name=expected_queue_name,
    )
    results = await arq_redis.all_job_results()
    assert results == [
        JobResult(
            function='foobar',
            args=(1, 2),
            kwargs={'c': 3},
            job_try=1,
            enqueue_time=IsNow(tz='utc'),
            success=True,
            result=42,
            start_time=IsNow(tz='utc'),
            finish_time=IsNow(tz='utc'),
            score=None,
            queue_name=expected_queue_name,
            job_id=j.job_id,
        )
    ]
Ejemplo n.º 3
0
async def test_deserialize_result(arq_redis: ArqRedis, worker):
    async def foobar(ctx, a, b):
        return a + b

    j = await arq_redis.enqueue_job('foobar', 1, 2)
    assert JobStatus.queued == await j.status()
    worker: Worker = worker(functions=[func(foobar, name='foobar')])
    await worker.run_check()
    assert await j.result(pole_delay=0) == 3
    assert await j.result(pole_delay=0) == 3
    info = await j.info()
    assert info.args == (1, 2)
    await arq_redis.set(result_key_prefix + j.job_id, b'invalid pickle data')
    with pytest.raises(DeserializationError, match='unable to deserialize job result'):
        assert await j.result(pole_delay=0) == 3
Ejemplo n.º 4
0
async def test_enqueue_job(arq_redis: ArqRedis, worker):
    async def foobar(ctx, *args, **kwargs):
        return 42

    j = await arq_redis.enqueue_job('foobar', 1, 2, c=3)
    assert isinstance(j, Job)
    assert JobStatus.queued == await j.status()
    worker: Worker = worker(functions=[func(foobar, name='foobar')])
    await worker.main()
    r = await j.result(pole_delay=0)
    assert r == 42
    assert JobStatus.complete == await j.status()
    info = await j.info()
    assert info == {
        'enqueue_time': CloseToNow(),
        'job_try': 1,
        'function': 'foobar',
        'args': (1, 2),
        'kwargs': {'c': 3},
        'success': True,
        'result': 42,
        'start_time': CloseToNow(),
        'finish_time': CloseToNow(),
        'score': None,
    }
    results = await arq_redis.all_job_results()
    assert results == [
        {
            'enqueue_time': CloseToNow(),
            'job_try': 1,
            'function': 'foobar',
            'args': (1, 2),
            'kwargs': {'c': 3},
            'success': True,
            'result': 42,
            'start_time': CloseToNow(),
            'finish_time': CloseToNow(),
            'job_id': j.job_id,
        }
    ]