Skip to content

Commit

Permalink
SDKTECHNO-271: fix client errors, add debounce to fix input UX issue
Browse files Browse the repository at this point in the history
  • Loading branch information
César Tailleur authored and EmilienLeroux committed Oct 18, 2024
1 parent c2a2594 commit 73e2847
Show file tree
Hide file tree
Showing 9 changed files with 25 additions and 107 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1 @@
002
001
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
# Check if the bucket exist, if not create it
bucket_exist = [True for bucket in s3_client.list_buckets()["Buckets"] if bucket["Name"] == s3_bucket_name]
if not bucket_exist:
# raise Exception(f"The bucket [{s3_bucket_name}] does not exist")
logging.info(f"Bucket [{s3_bucket_name}] does not exist, creating it")
s3_client.create_bucket(Bucket=s3_bucket_name)

Expand All @@ -28,8 +27,6 @@
app = Dash("AddOn Backup/Restore",
url_base_pathname=os.environ["SAAGIE_BASE_PATH"] + "/",
suppress_callback_exceptions=True)
# to run locally
# app = Dash(__name__)

app.title = "Saagie Backup/Restore apps storages"
app.layout = get_body_app()
Expand All @@ -52,11 +49,9 @@ def launch_restore():
#### selection de l'app à restaurer ####
@callback(
Output("date-select", "data"),
# Output("date-select", "value"),
Output("submit-restore", "disabled", allow_duplicate=True),
Output("date-select", "disabled"),
Input("app-select", "value"),
# Input("date-select", "value")
prevent_initial_call=True
)
def select_value(value_app):
Expand All @@ -68,38 +63,26 @@ def select_value(value_app):

dates = []
if not value_app == None:
print("a")
for project_id, apps_list in list_dates_backup.items():
for app_id in apps_list.keys():
if value_app == app_id:
# print(f"date = {apps_list[app_id]}")
dates = apps_list[app_id]
disabled = False
else:
print("b")
dates = []
disabled = True

print("-----------")
print(f"disabled= {disabled}")
print(f"dates= {dates}")
# print(f"value_date= {value_date}")
# return dates, value_date, disabled
return dates, disabled, disabled


@callback(
Output("submit-restore", "disabled"),
Input("date-select", "value"))
def select_value(value):
# print(f"value date backup= {value}")
retour = True
if not value == None:
# lancer la restauration de l'app avec la date de backup choisie
# time.sleep(5)
# retour "Restaurer à partir du backup du " + value
retour = False
return retour
return value == None


#### BOUTON RESTORE ####
Expand All @@ -115,14 +98,12 @@ def select_value(value):
prevent_initial_call=True
)
def prepare_restore(value_app, value_date, n_clicks):
# print("prepare_restore")
patched_children = Patch()
# if n_clicks:
if ctx.triggered_id == "submit-restore":
# recupération de l'app_id à restaurer
print(f"value_app= {value_app}")
logging.info(f"value_app= {value_app}")
# recupération de la date du backup à restaurer
print(f"value_date= {value_date}")
logging.info(f"value_date= {value_date}")
# mise à jour des envvar
message = ""

Expand Down Expand Up @@ -214,16 +195,14 @@ def show_selected_app(selectedRows):
)
def prepare_backup(selectedRows, rowData, n_clicks):
message_notification = ""
# if n_clicks:
if ctx.triggered_id == "submit-val":
# The button has been clicked, values is a list containing the active checklist values
# do something with values
# return something
# - afficher la liste des apps qui seront backupées dans la div 'selected-app'
# - mettre à jour la variable d'env SAAGIE_APP_BACKUP_LIST_APP_ID => comment trouver l'id du projet de l app courrante ?
# - lancer le script script_backup/__main__.py
# print(selectedRows)
# print(rowData)

list_selected_apps = []
for row in selectedRows:
list_selected_apps.append(row["app_id"])
Expand All @@ -250,7 +229,6 @@ def prepare_backup(selectedRows, rowData, n_clicks):
logging.info(f"----- End updating environment variables SAAGIE_APP_BACKUP_LIST_APP_ID")

launch_backup()
# time.sleep(2)
message_notification = 'The selected app(s) "{}" has(ve) been backuped '.format(backup_list_app_id)

return [], message_notification, {'display': 'block'}
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var dagcomponentfuncs = (window.dashAgGridComponentFunctions = window.dashAgGridComponentFunctions || {});

console.log('dagcomponentfuncs = ', dagcomponentfuncs);
dagcomponentfuncs.StockLink = function (props) {
console.log('props = ', props);
return React.createElement(
'a',
{
//href: 'https://finance.yahoo.com/quote/' + props.value,
href: props.value,
target : '_blank'
},
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def script_backup():

app_backup_baseName = 'saagie/saagie-app-storages-sub-app-backup'
app_backup_name = f'{app_backup_baseName}:{APP_BACKUP_VERSION}'
print(f"app_backup_name: {app_backup_name}")
logging.info(f"app_backup_name: {app_backup_name}")

# Get information to connect to Saagie
logging.info(f"Connect to Saagie ")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ def createStorageForRestoring(

volume_size=volume['size']
volume_name=volume['name']
# logging.info(f"Volume path: {path} - Volume size: {app_dict[path]}")
logging.info(f"===>volume_size : {volume_size}")
logging.info(f"===>volume_name : {volume_name}")

Expand Down Expand Up @@ -135,22 +134,17 @@ def script_restore():

storage_paths = []

# for path in backup_infos[max_date_str]:
for path in backup_infos[restore_date]:
logging.info(f"Restoring {path} for app [{app_id}]")
logging.info(f"path before if: {path}")
# s3_file_prefix = str(Path(f"{project_id}/{app_id}/{max_date_str}/{path}"))
s3_file_prefix = str(Path(f"{app_to_restore_project_id}/{app_id}/{restore_date}/{path}"))
if "/"+path not in app_dict:
logging.warning(f"Volume path: {path} not found in the app")
continue
logging.info(f"Volume path: {path} - Volume size: {app_dict['/'+path]}")

id_volume = ""
# Create the volume (Anne)
# Harmoniser la variable d = datetime.now()
#d = datetime.now()
# volumesWithPath=client_saagie.apps.get_info(app_id)['app']['currentVersion']['volumesWithPath']

logging.info(f"===>path : {path}")
logging.info(f"===>path_info : {path_info}")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,10 @@ def split_info(list_path, path_volume):
:param list_path:
:return:
"""
# Initialisation du dictionnaire pour stocker les informations
informations = {}

# Boucle sur chaque chemin
for chemin in list_path:
logging.info(f"chemin: {chemin}")
# Utilisation de l'expression régulière pour extraire les informations

for volume in path_volume:
escaped_pattern = re.escape(volume[1:])
Expand All @@ -79,26 +76,19 @@ def split_info(list_path, path_volume):
logging.info(f"regex: {regex}")
match = re.match(regex, chemin)

# match = re.match(r'.*/(\d{4}-\d{2}-\d{2})/(.+?)/', chemin)

logging.info(f"match: {match}")
if match:
date = match.group(1)
chemin_complet = match.group(2)
logging.info(f"chemin_complet: {chemin_complet}")

# Séparation du chemin complet pour obtenir le path
# path = chemin_complet.split('/')[0]
# logging.info(f"path: {path}")

# Création de la structure de données si elle n'existe pas encore
if date not in informations:
informations[date] = []
if chemin_complet not in informations[date]:
informations[date].append(chemin_complet)

# Affichage des informations

for date, paths in informations.items():
logging.info(f"Date: {date}")
for path in paths:
Expand All @@ -117,7 +107,7 @@ def list_projects(saagie, list_max_dates_backup, url, pf):
:return: pd.Dataframe
"""

retour = []
result = []
for project in saagie.projects.list()['projects']:
project_list_infos_app = saagie.apps.list_for_project(project_id=project["id"])['project']['apps']

Expand All @@ -127,22 +117,19 @@ def list_projects(saagie, list_max_dates_backup, url, pf):
last_backup = list_max_dates_backup[app["id"]]
else:
last_backup = "None"
# logging.info(f"----- last_backup : {last_backup}")

# on ne liste que les apps qui ont un volume lié
if app["linkedVolumes"]:
if len(app["linkedVolumes"]) > 0:
retour.append({"projet": project["name"],
result.append({"projet": project["name"],
"project_id": project["id"],
"app_name": app["name"],
"app_url": url_app,
# html pas interprété...
# "app_name": "<a href='"+url_app+"' target='_blank'>"+app["name"]+"</a>",
"app_id": app["id"],
"last_backup": last_backup
}
)
return pd.DataFrame(retour)
return pd.DataFrame(result)


def list_path_to_dict(list_path):
Expand All @@ -155,18 +142,14 @@ def list_path_to_dict(list_path):
projects_dict = {}
apps_list = {}

# print(f"list_path_tools.py : {list_path}")

# Boucle sur chaque chemin
for chemin in list_path:
# Utilisation de l'expression régulière pour extraire les informations
match = re.match(r'.*/(\d{4}-\d{2}-\d{2})/(.+?)/', chemin)
if match:
date = match.group(1)
# print(f"Date: {date}")
chemin_complet = match.group(2)
split_chemin = chemin.split(date)
# print(split_chemin)

project_id = split_chemin[0].split('/')[0]
app_id = split_chemin[0].split('/')[1]
Expand All @@ -181,14 +164,6 @@ def list_path_to_dict(list_path):
if date not in projects_dict[project_id][app_id]:
projects_dict[project_id][app_id].append(date)

# for project_id, apps_list in projects_dict.items():
# logging.info(f"project_id: {project_id}")
# for app_id, dates in apps_list.items():
# logging.info(f" app_id: {app_id}")
# for date in dates:
# logging.info(f" date: {date}")

# print(projects_dict)
return projects_dict


Expand All @@ -198,7 +173,6 @@ def get_max_date_list(projects_dict):
for app_id, dates in apps_list.items():
max_date = max([datetime.strptime(date, "%Y-%m-%d") for date in dates])
max_date_str = max_date.strftime("%Y-%m-%d")
# logging.info(f" max_date_str: {max_date_str}")

# Création de la structure de données si elle n'existe pas encore
if app_id not in list_max_dates_backup:
Expand All @@ -208,48 +182,35 @@ def get_max_date_list(projects_dict):


def get_select_data(saagie, projects_dict):
retour = []
result = []
# récupération de la liste des projets de la pf
projects_list = saagie.projects.list()['projects']

# print(f"projects_dict : {projects_dict}")

for project_id, apps_list in projects_dict.items():
# print(f"project_id : {project_id}")

# on parcourt la liste des projets de la pf pour trouver le nom
for project in projects_list:
if project_id == project["id"]:
# print(f"project['name'] : {project['name']}")
# print(f"apps_list : {apps_list}")
project_name = project['name']

# print(f"apps_list : {apps_list}")
# récupération de la liste des infos des apps du projet du dictionnaire des backups sur la pf
project_list_infos = saagie.apps.list_for_project(project_id=project_id)
# print(f"project_list_infos : {project_list_infos}")
project_list_infos_app = []
if (project_list_infos is not None) & (project_list_infos['project'] is not None):
project_list_infos_app = project_list_infos['project']['apps']
# print(f"project_list_infos_app : found")

list_apps_select = []
# on parcourt la liste des apps du dictionnaire des backups
for app_id in apps_list.keys():
# print(f"app_id : {app_id}")
# Pour chaque app du projet du dictionnaire des backups on parcourt la liste des infos app du projet en cours
for app in project_list_infos_app:
# quand on trouve l'id de l app dans la liste, on recupère le nom dans les infos
if app_id == app["id"]:
# print(f"app['id'] : {app['id']}")
list_apps_select.append({"value": app["id"], "label": project_name + " | " + app["name"]})
# print(f"list_apps_select : {list_apps_select}")

retour.append(
result.append(
{
"group": project_name,
"items": list_apps_select
}
)
# print(f"retour : {retour}")
return retour
return result
Loading

0 comments on commit 73e2847

Please sign in to comment.