mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-11 18:39:30 +00:00
feature(backups): job progress logs
This commit is contained in:
parent
ca036b294a
commit
135fb0c42d
|
@ -133,18 +133,27 @@ class Jobs:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def log_status_update(job: Job, status: JobStatus):
|
def log_status_update(job: Job, status: JobStatus):
|
||||||
redis = RedisPool().get_connection()
|
redis = RedisPool().get_connection()
|
||||||
key = _redis_log_key_from_uuid(job.uid)
|
key = _status_log_key_from_uuid(job.uid)
|
||||||
if redis.exists(key):
|
if redis.exists(key):
|
||||||
assert redis.type(key) == "list"
|
assert redis.type(key) == "list"
|
||||||
redis.lpush(key, status.value)
|
redis.lpush(key, status.value)
|
||||||
redis.expire(key, 10)
|
redis.expire(key, 10)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def log_progress_update(job: Job, progress: int):
|
||||||
|
redis = RedisPool().get_connection()
|
||||||
|
key = _progress_log_key_from_uuid(job.uid)
|
||||||
|
if redis.exists(key):
|
||||||
|
assert redis.type(key) == "list"
|
||||||
|
redis.lpush(key, progress)
|
||||||
|
redis.expire(key, 10)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def status_updates(job: Job) -> typing.List[JobStatus]:
|
def status_updates(job: Job) -> typing.List[JobStatus]:
|
||||||
result = []
|
result = []
|
||||||
|
|
||||||
redis = RedisPool().get_connection()
|
redis = RedisPool().get_connection()
|
||||||
key = _redis_log_key_from_uuid(job.uid)
|
key = _status_log_key_from_uuid(job.uid)
|
||||||
if not redis.exists(key):
|
if not redis.exists(key):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
|
@ -156,6 +165,23 @@ class Jobs:
|
||||||
raise ValueError("impossible job status: " + status) from e
|
raise ValueError("impossible job status: " + status) from e
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def progress_updates(job: Job) -> typing.List[int]:
|
||||||
|
result = []
|
||||||
|
|
||||||
|
redis = RedisPool().get_connection()
|
||||||
|
key = _progress_log_key_from_uuid(job.uid)
|
||||||
|
if not redis.exists(key):
|
||||||
|
return []
|
||||||
|
|
||||||
|
progress_strings = redis.lrange(key, 0, -1)
|
||||||
|
for progress in progress_strings:
|
||||||
|
try:
|
||||||
|
result.append(int(progress))
|
||||||
|
except KeyError as e:
|
||||||
|
raise ValueError("impossible job progress: " + progress) from e
|
||||||
|
return result
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def update(
|
def update(
|
||||||
job: Job,
|
job: Job,
|
||||||
|
@ -178,6 +204,7 @@ class Jobs:
|
||||||
job.status_text = status_text
|
job.status_text = status_text
|
||||||
if progress is not None:
|
if progress is not None:
|
||||||
job.progress = progress
|
job.progress = progress
|
||||||
|
Jobs.log_progress_update(job, progress)
|
||||||
job.status = status
|
job.status = status
|
||||||
Jobs.log_status_update(job, status)
|
Jobs.log_status_update(job, status)
|
||||||
job.updated_at = datetime.datetime.now()
|
job.updated_at = datetime.datetime.now()
|
||||||
|
@ -235,10 +262,14 @@ def _redis_key_from_uuid(uuid_string):
|
||||||
return "jobs:" + str(uuid_string)
|
return "jobs:" + str(uuid_string)
|
||||||
|
|
||||||
|
|
||||||
def _redis_log_key_from_uuid(uuid_string):
|
def _status_log_key_from_uuid(uuid_string):
|
||||||
return STATUS_LOGS_PREFIX + str(uuid_string)
|
return STATUS_LOGS_PREFIX + str(uuid_string)
|
||||||
|
|
||||||
|
|
||||||
|
def _progress_log_key_from_uuid(uuid_string):
|
||||||
|
return PROGRESS_LOGS_PREFIX + str(uuid_string)
|
||||||
|
|
||||||
|
|
||||||
def _store_job_as_hash(redis, redis_key, model):
|
def _store_job_as_hash(redis, redis_key, model):
|
||||||
for key, value in model.dict().items():
|
for key, value in model.dict().items():
|
||||||
if isinstance(value, uuid.UUID):
|
if isinstance(value, uuid.UUID):
|
||||||
|
|
Loading…
Reference in a new issue