mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-02-02 14:16:38 +00:00
feature(jobs): set ttl via method
This commit is contained in:
parent
07aaa21602
commit
0912ac1831
|
@ -224,6 +224,14 @@ class Jobs:
|
|||
|
||||
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
|
||||
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
|
||||
|
||||
|
||||
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):
|
||||
jobs = jobs_with_one_job
|
||||
test_job = jobs_with_one_job.get_jobs()[0]
|
||||
|
|
Loading…
Reference in a new issue