mirror of
https://git.selfprivacy.org/SelfPrivacy/selfprivacy-rest-api.git
synced 2025-01-27 11:16:35 +00:00
refactor(backups): refactor realtime updating
This commit is contained in:
parent
b1d0a80963
commit
9fab596f91
|
@ -110,19 +110,10 @@ class ResticBackuper(AbstractBackuper):
|
||||||
)
|
)
|
||||||
|
|
||||||
messages = []
|
messages = []
|
||||||
|
job = get_backup_job(get_service_by_id(repo_name))
|
||||||
try:
|
try:
|
||||||
for raw_message in ResticBackuper.output_yielder(backup_command):
|
for raw_message in ResticBackuper.output_yielder(backup_command):
|
||||||
message = self.parse_json_output(raw_message)
|
message = self.parse_message(raw_message, job)
|
||||||
if message["message_type"] == "status":
|
|
||||||
job = get_backup_job(get_service_by_id(repo_name))
|
|
||||||
if job is not None: # only update status if we run under some job
|
|
||||||
Jobs.update(
|
|
||||||
job,
|
|
||||||
JobStatus.RUNNING,
|
|
||||||
progress=ResticBackuper.progress_from_status_message(
|
|
||||||
message
|
|
||||||
),
|
|
||||||
)
|
|
||||||
messages.append(message)
|
messages.append(message)
|
||||||
return ResticBackuper._snapshot_from_backup_messages(messages, repo_name)
|
return ResticBackuper._snapshot_from_backup_messages(messages, repo_name)
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
|
@ -135,9 +126,16 @@ class ResticBackuper(AbstractBackuper):
|
||||||
return ResticBackuper._snapshot_from_fresh_summary(message, repo_name)
|
return ResticBackuper._snapshot_from_fresh_summary(message, repo_name)
|
||||||
raise ValueError("no summary message in restic json output")
|
raise ValueError("no summary message in restic json output")
|
||||||
|
|
||||||
@staticmethod
|
def parse_message(self, raw_message, job=None) -> object:
|
||||||
def progress_from_status_message(message: object) -> int:
|
message = self.parse_json_output(raw_message)
|
||||||
return int(message["percent_done"])
|
if message["message_type"] == "status":
|
||||||
|
if job is not None: # only update status if we run under some job
|
||||||
|
Jobs.update(
|
||||||
|
job,
|
||||||
|
JobStatus.RUNNING,
|
||||||
|
progress=int(message["percent_done"]),
|
||||||
|
)
|
||||||
|
return message
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _snapshot_from_fresh_summary(message: object, repo_name) -> Snapshot:
|
def _snapshot_from_fresh_summary(message: object, repo_name) -> Snapshot:
|
||||||
|
|
Loading…
Reference in a new issue