Add notification for migrations failure

This commit is contained in:
= 2024-09-16 17:37:04 -04:00
parent 52a6e9ae59
commit 6d2accfbc8
5 changed files with 66 additions and 8 deletions

1
.gitignore vendored
View File

@ -38,3 +38,4 @@ docker/*
!docker/docker-compose.yml
lang_sort_log.txt
lang_sort.txt
app/migrations/status

View File

@ -58,6 +58,7 @@ class Helpers:
def __init__(self):
self.root_dir = os.path.abspath(os.path.curdir)
self.read_annc = False
self.config_dir = os.path.join(self.root_dir, "app", "config")
self.webroot = os.path.join(self.root_dir, "app", "frontend")
self.servers_dir = os.path.join(self.root_dir, "servers")
@ -615,12 +616,49 @@ class Helpers:
return version_data
def get_announcements(self):
def check_migrations(self) -> None:
if self.read_annc == False:
self.read_annc = True
for file in os.listdir(
os.path.join(self.root_dir, "app", "migrations", "status")
):
with open(
os.path.join(self.root_dir, "app", "migrations", "status", file),
"r",
encoding="utf-8",
) as notif_file:
file_json = json.load(notif_file)
for notif in file_json:
if not file_json[notif].get("status"):
self.migration_notifications.append(file_json[notif])
def get_announcements(self, lang=None):
try:
data = []
response = requests.get("https://craftycontrol.com/notify", timeout=2)
data = json.loads(response.content)
data.extend(self.migration_notifications)
if not lang:
lang = self.get_setting("language")
self.check_migrations()
for migration_warning in self.migration_notifications:
if not migration_warning.get("status"):
data.append(
{
"id": migration_warning.get("pid"),
"title": self.translation.translate(
"notify",
f"{migration_warning.get('type')}_title",
lang,
),
"date": "",
"desc": self.translation.translate(
"notify",
f"{migration_warning.get('type')}_desc",
lang,
),
"link": "",
}
)
if self.update_available:
data.append(self.update_available)
return data

View File

@ -29,7 +29,7 @@ class ApiAnnounceIndexHandler(BaseApiHandler):
_,
) = auth_data
data = self.helper.get_announcements()
data = self.helper.get_announcements(auth_data[4]["lang"])
if not data:
return self.finish_json(
424,

View File

@ -25,6 +25,8 @@ def migrate(migrator: Migrator, database, **kwargs):
"""
Write your migrations here.
"""
backup_migration_status = True
schedule_migration_status = True
db = database
Console.info("Starting Backups migrations")
Console.info(
@ -241,6 +243,7 @@ def migrate(migrator: Migrator, database, **kwargs):
try:
backup = NewBackups.get(NewBackups.server_id == schedule.server_id)
except:
schedule_migration_status = False
Console.error(
"Could not find backup with selected server ID. Omitting from register."
)
@ -272,17 +275,29 @@ def migrate(migrator: Migrator, database, **kwargs):
# Rename the new table to backups
migrator.rename_table("new_schedules", "schedules")
with open("status/20240308_multi-backup.json", "w", encoding="utf-8") as file:
with open(
os.path.join(
os.path.abspath(os.path.curdir),
"app",
"migrations",
"status",
"20240308_multi-backup.json",
),
"w",
encoding="utf-8",
) as file:
file.write(
json.dumps(
{
"backup_migration": {
"type": "backup",
"status": backup_migration_status,
"pid": uuid.uuid4(),
"pid": str(uuid.uuid4()),
},
"schedule_migration": {
"type": "schedule",
"status": schedule_migration_status,
"pid": uuid.uuid4(),
"pid": str(uuid.uuid4()),
},
}
)

View File

@ -235,7 +235,11 @@
"finishedPreparing": "We've finished preparing your support logs. Please click download to download",
"logout": "Logout",
"preparingLogs": " Please wait while we prepare your logs... We`ll send a notification when they`re ready. This may take a while for large deployments.",
"supportLogs": "Support Logs"
"supportLogs": "Support Logs",
"backup_title": "Backup Migration Warning",
"backup_desc": "We detected the backup migration may have partially or fully failed. Please confirm your backups records on the backups tab.",
"schedule_title": "Schedules Migration Warning",
"schedule_desc": "We detected some or all of your scheduled tasks were not successfully transfered during the upgrade. Please confirm your schedules in the schedules tab."
},
"offline": {
"offline": "Offline",