Merge pull request #80 from vexxhost/improve-result-report
Improve report content
diff --git a/staffeln/conductor/manager.py b/staffeln/conductor/manager.py
index 6869caa..33fa22b 100755
--- a/staffeln/conductor/manager.py
+++ b/staffeln/conductor/manager.py
@@ -121,27 +121,27 @@
LOG.info(_("Updating backup task queue..."))
self.controller.refresh_openstacksdk()
self.controller.refresh_backup_result()
- current_tasks = self.controller.get_queues()
- self.controller.create_queue(current_tasks)
+ filters = {"backup_status": constants.BACKUP_WIP}
+ current_wip_tasks = self.controller.get_queues(filters=filters)
+ filters["backup_status"] = constants.BACKUP_PLANNED
+ current_plan_tasks = self.controller.get_queues(filters=filters)
+ self.controller.create_queue(current_plan_tasks + current_wip_tasks)
def _report_backup_result(self):
report_period_mins = CONF.conductor.report_period
threshold_strtime = datetime.now() - timedelta(minutes=report_period_mins)
- filters = {
- "created_at__lt": threshold_strtime.astimezone(),
- }
+ filters = {"created_at__lt": threshold_strtime.astimezone()}
old_tasks = self.controller.get_queues(filters=filters)
- if old_tasks:
- filters = {
- "backup_status": constants.BACKUP_COMPLETED,
- }
- success_tasks = self.controller.get_queues(filters=filters)
- filters["backup_status"] = constants.BACKUP_FAILED
- failed_tasks = self.controller.get_queues(filters=filters)
- if success_tasks or failed_tasks:
+ for task in old_tasks:
+ if task.backup_status in (
+ constants.BACKUP_COMPLETED,
+ constants.BACKUP_FAILED,
+ ):
+ LOG.info(_("Reporting finished backup tasks..."))
self.controller.publish_backup_result()
# Purge backup queue tasks
self.controller.purge_backups()
+ return
def backup_engine(self, backup_service_period):
LOG.info("Backup manager started %s" % str(time.time()))
diff --git a/staffeln/conductor/result.py b/staffeln/conductor/result.py
index af7eb5f..1e31733 100644
--- a/staffeln/conductor/result.py
+++ b/staffeln/conductor/result.py
@@ -93,11 +93,11 @@
if project_id in project_success:
success_volumes = "<br>".join(
[
- "Volume ID: %s, Backup ID: %s, backup mode: %s"
- % (
- str(e.volume_id),
- str(e.backup_id),
- "Incremental" if e.incremental else "Full",
+ (
+ f"Volume ID: {str(e.volume_id)}, Backup ID: {str(e.backup_id)}, "
+ f"Backup mode: {'Incremental' if e.incremental else 'Full'}, "
+ f"Created at: {str(e.created_at)}, Last updated at: "
+ f"{str(e.updated_at)}"
)
for e in project_success[project_id]
]
@@ -107,7 +107,11 @@
if project_id in project_failed:
failed_volumes = "<br>".join(
[
- "Volume ID: %s, Reason: %s" % (str(e.volume_id), str(e.reason))
+ (
+ f"Volume ID: {str(e.volume_id)}, Reason: {str(e.reason)}, "
+ f"Created at: {str(e.created_at)}, Last updated at: "
+ f"{str(e.updated_at)}"
+ )
for e in project_failed[project_id]
]
)
@@ -120,7 +124,7 @@
quota_color = "YALLOW"
else:
quota_color = "GREEN"
- html = html.replace("${QUOTA_USAGE}", quota_usage)
+ html = html.replace("${QUOTA_USAGE}", str(quota_usage))
html = html.replace("${QUOTA_COLLOR}", quota_color)
html = html.replace("${QUOTA_LIMIT}", str(quota["limit"]))
html = html.replace("${QUOTA_IN_USE}", str(quota["in_use"]))
diff --git a/staffeln/db/sqlalchemy/api.py b/staffeln/db/sqlalchemy/api.py
index adfa7a7..3526b93 100644
--- a/staffeln/db/sqlalchemy/api.py
+++ b/staffeln/db/sqlalchemy/api.py
@@ -132,6 +132,7 @@
"volume_id",
"instance_id",
"backup_status",
+ "created_at",
]
return self._add_filters(