Esempio n. 1
0
def test_finish_job_sets_results_ttl(redis):
    """Finish job sets results TTL."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert (yield from redis.ttl(job_key(stubs.job_id))) == 500
Esempio n. 2
0
def test_finish_job_sets_results_ttl(redis):
    """Finish job sets results TTL."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert (yield from redis.ttl(job_key(stubs.job_id))) == 500
Esempio n. 3
0
def test_finish_job_started_registry(redis):
    """Finish job removes job from started job registry."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert not (yield from started_jobs(redis, stubs.queue))
Esempio n. 4
0
def test_finish_job_started_registry(redis):
    """Finish job removes job from started job registry."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert not (yield from started_jobs(redis, stubs.queue))
Esempio n. 5
0
def test_finish_job_sets_corresponding_status(redis):
    """Finish job sets corresponding status."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert (yield from job_status(redis, stubs.job_id)) == JobStatus.FINISHED.encode()
Esempio n. 6
0
def test_finish_job_sets_ended_at(redis):
    """Finish job sets ended at field."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    ended_at = yield from redis.hget(job_key(stubs.job_id), 'ended_at')
    assert ended_at == utcformat(utcnow()).encode()
Esempio n. 7
0
def test_finish_job_sets_ended_at(redis):
    """Finish job sets ended at field."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    ended_at = yield from redis.hget(job_key(stubs.job_id), 'ended_at')
    assert ended_at == utcformat(utcnow()).encode()
Esempio n. 8
0
def test_finish_job_dependents_defered_registry(redis):
    """Finish job will remove its dependents from deferred job registries."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert not (yield from deferred_jobs(redis, queue))
Esempio n. 9
0
def test_finish_job_cleanup_dependents(redis):
    """Finish job will cleanup parent job dependents set."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert not (yield from redis.smembers(dependents(stubs.job_id)))
Esempio n. 10
0
def test_finish_job_enqueue_dependents_status(redis):
    """Finish job will set dependents status to QUEUED."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert (yield from redis.hget(job_key(stubs.child_job_id), 'status')) == JobStatus.QUEUED.encode()
Esempio n. 11
0
def test_finish_job_enqueue_dependents(redis):
    """Finish job will enqueue its dependents."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == [stubs.child_job_id.encode()]
Esempio n. 12
0
def test_finish_job_finished_registry(redis):
    """Finish job add job to the finished job registry."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    finish = yield from redis.zrange(finished_registry(queue), withscores=True)
    assert finish == [stubs.job_id.encode(), current_timestamp() + 500]
Esempio n. 13
0
def test_finish_job_non_expired_job(redis):
    """Finish job persist non expired job."""

    yield from enqueue_job(redis=redis, result_ttl=None, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    queue = stored_spec[b'origin'].decode()
    stored_id = stored_id.decode()
    timeout = stored_spec[b'timeout']
    result_ttl = stored_spec[b'result_ttl']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id, result_ttl=result_ttl)
    assert (yield from redis.ttl(job_key(stubs.job_id))) == -1
Esempio n. 14
0
def test_finish_job_remove_results_zero_ttl(redis):
    """Finish job removes jobs with zero TTL."""

    yield from enqueue_job(redis=redis, result_ttl=0, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    queue = stored_spec[b'origin'].decode()
    stored_id = stored_id.decode()
    timeout = stored_spec[b'timeout']
    result_ttl = stored_spec[b'result_ttl']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id, result_ttl=result_ttl)
    assert not (yield from redis.exists(job_key(stubs.job_id)))
Esempio n. 15
0
def test_finish_job_sets_corresponding_status(redis):
    """Finish job sets corresponding status."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert (yield from
            job_status(redis, stubs.job_id)) == JobStatus.FINISHED.encode()
Esempio n. 16
0
def test_finish_job_dependents_defered_registry(redis):
    """Finish job will remove its dependents from deferred job registries."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert not (yield from deferred_jobs(redis, queue))
Esempio n. 17
0
def test_enqueue_job_finished_dependency(redis):
    """Enqueue job immediately if its dependency already finished."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    assert (yield from redis.lrange(queue_key(stubs.queue), 0, -1)) == [stubs.child_job_id.encode()]
Esempio n. 18
0
def test_finish_job_cleanup_dependents(redis):
    """Finish job will cleanup parent job dependents set."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert not (yield from redis.smembers(dependents(stubs.job_id)))
Esempio n. 19
0
def test_finish_job_finished_registry(redis):
    """Finish job add job to the finished job registry."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    finish = yield from redis.zrange(finished_registry(queue), withscores=True)
    assert finish == [stubs.job_id.encode(), current_timestamp() + 500]
Esempio n. 20
0
def test_finish_job_non_expired_job(redis):
    """Finish job persist non expired job."""

    yield from enqueue_job(redis=redis, result_ttl=None, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    queue = stored_spec[b'origin'].decode()
    stored_id = stored_id.decode()
    timeout = stored_spec[b'timeout']
    result_ttl = stored_spec[b'result_ttl']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id, result_ttl=result_ttl)
    assert (yield from redis.ttl(job_key(stubs.job_id))) == -1
Esempio n. 21
0
def test_finish_job_remove_results_zero_ttl(redis):
    """Finish job removes jobs with zero TTL."""

    yield from enqueue_job(redis=redis, result_ttl=0, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    queue = stored_spec[b'origin'].decode()
    stored_id = stored_id.decode()
    timeout = stored_spec[b'timeout']
    result_ttl = stored_spec[b'result_ttl']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id, result_ttl=result_ttl)
    assert not (yield from redis.exists(job_key(stubs.job_id)))
Esempio n. 22
0
def test_enqueue_job_finished_dependency(redis):
    """Enqueue job immediately if its dependency already finished."""

    yield from enqueue_job(redis=redis, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    assert (yield from redis.lrange(queue_key(stubs.queue), 0,
                                    -1)) == [stubs.child_job_id.encode()]
Esempio n. 23
0
def test_finish_job_dependents_enqueue_date(redis):
    """Finish job will enqueue its dependents with proper date field."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    enqueued_at = yield from redis.hget(job_key(stubs.job_id), 'enqueued_at')
    assert enqueued_at == utcformat(utcnow()).encode()
Esempio n. 24
0
def test_finish_job_enqueue_dependents_status(redis):
    """Finish job will set dependents status to QUEUED."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert (yield from redis.hget(job_key(stubs.child_job_id),
                                  'status')) == JobStatus.QUEUED.encode()
Esempio n. 25
0
def test_finish_job_enqueue_dependents(redis):
    """Finish job will enqueue its dependents."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    assert (yield from redis.lrange(queue_key(stubs.queue), 0,
                                    -1)) == [stubs.child_job_id.encode()]
Esempio n. 26
0
def test_finish_job_finished_registry_negative_ttl(redis):
    """Don't use current timestamp in job score with empty result TTL."""

    yield from enqueue_job(redis=redis, result_ttl=None, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    queue = stored_spec[b'origin'].decode()
    stored_id = stored_id.decode()
    timeout = stored_spec[b'timeout']
    result_ttl = stored_spec[b'result_ttl']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id, result_ttl=result_ttl)
    finish = yield from redis.zrange(finished_registry(queue), withscores=True)
    assert finish == [stubs.job_id.encode(), -1]
Esempio n. 27
0
def test_finish_job_finished_registry_negative_ttl(redis):
    """Don't use current timestamp in job score with empty result TTL."""

    yield from enqueue_job(redis=redis, result_ttl=None, **stubs.job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    queue = stored_spec[b'origin'].decode()
    stored_id = stored_id.decode()
    timeout = stored_spec[b'timeout']
    result_ttl = stored_spec[b'result_ttl']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id, result_ttl=result_ttl)
    finish = yield from redis.zrange(finished_registry(queue), withscores=True)
    assert finish == [stubs.job_id.encode(), -1]
Esempio n. 28
0
def test_finish_job_dependents_enqueue_date(redis):
    """Finish job will enqueue its dependents with proper date field."""

    yield from enqueue_job(redis=redis, **stubs.job)
    yield from enqueue_job(redis=redis, **stubs.child_job)
    stored_id, stored_spec = yield from dequeue_job(redis, stubs.queue)
    stored_id = stored_id.decode()
    queue = stored_spec[b'origin'].decode()
    timeout = stored_spec[b'timeout']
    yield from start_job(redis, queue, stored_id, timeout)
    yield from finish_job(redis, queue, stored_id)
    enqueued_at = yield from redis.hget(job_key(stubs.job_id), 'enqueued_at')
    assert enqueued_at == utcformat(utcnow()).encode()