Skip to content

Commit

Permalink
Continue restore if a taskdef fails to be validated rockstor#2355
Browse files Browse the repository at this point in the history
Currently, a failed validation will fail the entire restore_scheduled_tasks() process.

This commit instead catches any Exception during this process and logs it as INFO
before moving on to the next task definition to be restored.
  • Loading branch information
FroggyFlox committed Feb 26, 2023
1 parent 0950ce5 commit fe71be8
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions src/rockstor/storageadmin/views/config_backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def validate_taskdef_meta(sa_ml, taskdef_meta, task_type):
"writable": true,
"visible": true,
"prefix": "snap_daily_ts01",
"share": "77",pass
"share": "77",
"max_count": "4"
}
"""
Expand Down Expand Up @@ -232,24 +232,27 @@ def restore_scheduled_tasks(ml, sa_ml):
tasks = []
for m in ml:
if m["model"] == "smart_manager.taskdefinition":
name = m["fields"]["name"]
task_type = m["fields"]["task_type"]
crontab = m["fields"]["crontab"]
crontabwindow = m["fields"]["crontabwindow"]
enabled = m["fields"]["enabled"]
json_meta = m["fields"]["json_meta"]
if json_meta is not None:
jmeta = json.loads(json_meta)
jmeta = validate_taskdef_meta(sa_ml, jmeta, task_type)
taskdef = {
"name": name,
"task_type": task_type,
"crontab": crontab,
"crontabwindow": crontabwindow,
"enabled": enabled,
"meta": jmeta,
}
tasks.append(taskdef)
try:
name = m["fields"]["name"]
task_type = m["fields"]["task_type"]
crontab = m["fields"]["crontab"]
crontabwindow = m["fields"]["crontabwindow"]
enabled = m["fields"]["enabled"]
json_meta = m["fields"]["json_meta"]
if json_meta is not None:
jmeta = json.loads(json_meta)
jmeta = validate_taskdef_meta(sa_ml, jmeta, task_type)
taskdef = {
"name": name,
"task_type": task_type,
"crontab": crontab,
"crontabwindow": crontabwindow,
"enabled": enabled,
"meta": jmeta,
}
tasks.append(taskdef)
except Exception as e:
logger.info("An unexpected error occurred while trying to restore a task ({}): {}".format(name, e))
for t in tasks:
generic_post("{}/sm/tasks".format(BASE_URL), t)
logger.info("Finished restoring scheduled tasks.")
Expand Down

0 comments on commit fe71be8

Please sign in to comment.