mirror of
https://gitlab.com/crafty-controller/crafty-4.git
synced 2025-01-18 09:05:15 +01:00
Add notification for migrations failure
This commit is contained in:
parent
52a6e9ae59
commit
6d2accfbc8
1
.gitignore
vendored
1
.gitignore
vendored
@ -38,3 +38,4 @@ docker/*
|
|||||||
!docker/docker-compose.yml
|
!docker/docker-compose.yml
|
||||||
lang_sort_log.txt
|
lang_sort_log.txt
|
||||||
lang_sort.txt
|
lang_sort.txt
|
||||||
|
app/migrations/status
|
||||||
|
@ -58,6 +58,7 @@ class Helpers:
|
|||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.root_dir = os.path.abspath(os.path.curdir)
|
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.config_dir = os.path.join(self.root_dir, "app", "config")
|
||||||
self.webroot = os.path.join(self.root_dir, "app", "frontend")
|
self.webroot = os.path.join(self.root_dir, "app", "frontend")
|
||||||
self.servers_dir = os.path.join(self.root_dir, "servers")
|
self.servers_dir = os.path.join(self.root_dir, "servers")
|
||||||
@ -615,12 +616,49 @@ class Helpers:
|
|||||||
|
|
||||||
return version_data
|
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:
|
try:
|
||||||
data = []
|
data = []
|
||||||
response = requests.get("https://craftycontrol.com/notify", timeout=2)
|
response = requests.get("https://craftycontrol.com/notify", timeout=2)
|
||||||
data = json.loads(response.content)
|
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:
|
if self.update_available:
|
||||||
data.append(self.update_available)
|
data.append(self.update_available)
|
||||||
return data
|
return data
|
||||||
|
@ -29,7 +29,7 @@ class ApiAnnounceIndexHandler(BaseApiHandler):
|
|||||||
_,
|
_,
|
||||||
) = auth_data
|
) = auth_data
|
||||||
|
|
||||||
data = self.helper.get_announcements()
|
data = self.helper.get_announcements(auth_data[4]["lang"])
|
||||||
if not data:
|
if not data:
|
||||||
return self.finish_json(
|
return self.finish_json(
|
||||||
424,
|
424,
|
||||||
|
@ -25,6 +25,8 @@ def migrate(migrator: Migrator, database, **kwargs):
|
|||||||
"""
|
"""
|
||||||
Write your migrations here.
|
Write your migrations here.
|
||||||
"""
|
"""
|
||||||
|
backup_migration_status = True
|
||||||
|
schedule_migration_status = True
|
||||||
db = database
|
db = database
|
||||||
Console.info("Starting Backups migrations")
|
Console.info("Starting Backups migrations")
|
||||||
Console.info(
|
Console.info(
|
||||||
@ -241,6 +243,7 @@ def migrate(migrator: Migrator, database, **kwargs):
|
|||||||
try:
|
try:
|
||||||
backup = NewBackups.get(NewBackups.server_id == schedule.server_id)
|
backup = NewBackups.get(NewBackups.server_id == schedule.server_id)
|
||||||
except:
|
except:
|
||||||
|
schedule_migration_status = False
|
||||||
Console.error(
|
Console.error(
|
||||||
"Could not find backup with selected server ID. Omitting from register."
|
"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
|
# Rename the new table to backups
|
||||||
migrator.rename_table("new_schedules", "schedules")
|
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(
|
file.write(
|
||||||
json.dumps(
|
json.dumps(
|
||||||
{
|
{
|
||||||
"backup_migration": {
|
"backup_migration": {
|
||||||
|
"type": "backup",
|
||||||
"status": backup_migration_status,
|
"status": backup_migration_status,
|
||||||
"pid": uuid.uuid4(),
|
"pid": str(uuid.uuid4()),
|
||||||
},
|
},
|
||||||
"schedule_migration": {
|
"schedule_migration": {
|
||||||
|
"type": "schedule",
|
||||||
"status": schedule_migration_status,
|
"status": schedule_migration_status,
|
||||||
"pid": uuid.uuid4(),
|
"pid": str(uuid.uuid4()),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
@ -235,7 +235,11 @@
|
|||||||
"finishedPreparing": "We've finished preparing your support logs. Please click download to download",
|
"finishedPreparing": "We've finished preparing your support logs. Please click download to download",
|
||||||
"logout": "Logout",
|
"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.",
|
"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": "Offline",
|
"offline": "Offline",
|
||||||
|
Loading…
x
Reference in New Issue
Block a user