mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2024-11-19 00:39:15 +00:00
Add TTL to storage of finished or failed jobs
Defaulting to 10 days.
This commit is contained in:
parent
244851c7cc
commit
d6ef01c0c7
|
@ -24,6 +24,8 @@ from pydantic import BaseModel
|
||||||
|
|
||||||
from selfprivacy_api.utils.redis_pool import RedisPool
|
from selfprivacy_api.utils.redis_pool import RedisPool
|
||||||
|
|
||||||
|
JOB_EXPIRATION_SECONDS = 10 * 24 * 60 * 60 # ten days
|
||||||
|
|
||||||
|
|
||||||
class JobStatus(Enum):
|
class JobStatus(Enum):
|
||||||
"""
|
"""
|
||||||
|
@ -150,6 +152,8 @@ class Jobs:
|
||||||
key = redis_key_from_uuid(job.uid)
|
key = redis_key_from_uuid(job.uid)
|
||||||
if r.exists(key):
|
if r.exists(key):
|
||||||
store_job_as_hash(r, key, job)
|
store_job_as_hash(r, key, job)
|
||||||
|
if status in (JobStatus.FINISHED, JobStatus.ERROR):
|
||||||
|
r.expire(key, JOB_EXPIRATION_SECONDS)
|
||||||
|
|
||||||
return job
|
return job
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from selfprivacy_api.jobs import Jobs, JobStatus
|
from selfprivacy_api.jobs import Jobs, JobStatus
|
||||||
|
import selfprivacy_api.jobs as jobsmodule
|
||||||
|
|
||||||
|
|
||||||
def test_jobs(authorized_client, jobs_file, shared_datadir):
|
def test_jobs(authorized_client, jobs_file, shared_datadir):
|
||||||
|
@ -30,6 +31,19 @@ def test_jobs(authorized_client, jobs_file, shared_datadir):
|
||||||
|
|
||||||
assert jobs.get_jobs() == [test_job]
|
assert jobs.get_jobs() == [test_job]
|
||||||
|
|
||||||
|
backup = jobsmodule.JOB_EXPIRATION_SECONDS
|
||||||
|
jobsmodule.JOB_EXPIRATION_SECONDS = 0
|
||||||
|
|
||||||
|
jobs.update(
|
||||||
|
job=test_job,
|
||||||
|
status=JobStatus.FINISHED,
|
||||||
|
status_text="Yaaay!",
|
||||||
|
progress=100,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert jobs.get_jobs() == []
|
||||||
|
jobsmodule.JOB_EXPIRATION_SECONDS = backup
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def mock_subprocess_run(mocker):
|
def mock_subprocess_run(mocker):
|
||||||
|
|
Loading…
Reference in a new issue