feature(jobs): set ttl via method
parent
07aaa21602
commit
0912ac1831
|
@ -224,6 +224,14 @@ class Jobs:
|
||||||
|
|
||||||
return job
|
return job
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def set_expiration(job: Job, expiration_seconds: int) -> Job:
|
||||||
|
redis = RedisPool().get_connection()
|
||||||
|
key = _redis_key_from_uuid(job.uid)
|
||||||
|
if redis.exists(key):
|
||||||
|
redis.expire(key, expiration_seconds)
|
||||||
|
return job
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def get_job(uid: str) -> typing.Optional[Job]:
|
def get_job(uid: str) -> typing.Optional[Job]:
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -49,6 +49,12 @@ def test_remove_get_nonexistent(jobs_with_one_job):
|
||||||
assert jobs_with_one_job.get_job(uid_str) is None
|
assert jobs_with_one_job.get_job(uid_str) is None
|
||||||
|
|
||||||
|
|
||||||
|
def test_set_zeroing_ttl(jobs_with_one_job):
|
||||||
|
test_job = jobs_with_one_job.get_jobs()[0]
|
||||||
|
jobs_with_one_job.set_expiration(test_job, 0)
|
||||||
|
assert jobs_with_one_job.get_jobs() == []
|
||||||
|
|
||||||
|
|
||||||
def test_jobs(jobs_with_one_job):
|
def test_jobs(jobs_with_one_job):
|
||||||
jobs = jobs_with_one_job
|
jobs = jobs_with_one_job
|
||||||
test_job = jobs_with_one_job.get_jobs()[0]
|
test_job = jobs_with_one_job.get_jobs()[0]
|
||||||
|
|
Loading…
Reference in New Issue