RegisterBackupCallback registers a callback for backup state changes. Returns a function to unregister the callback.
(callback func())
| 782 | // RegisterBackupCallback registers a callback for backup state changes. |
| 783 | // Returns a function to unregister the callback. |
| 784 | func (a *App) RegisterBackupCallback(callback func()) func() { |
| 785 | return a.poller.Subscribe(func(task *taskpoller.TaskInfo) { |
| 786 | a.QueueUpdateDraw(func() { |
| 787 | if task.Status == "stopped" { |
| 788 | if task.ExitStatus == "OK" { |
| 789 | a.header.ShowSuccess(fmt.Sprintf("Backup for VM %d on %s completed successfully!", task.VMID, task.Node)) |
| 790 | } else { |
| 791 | a.header.ShowError(fmt.Sprintf("Backup for VM %d on %s failed: %s", task.VMID, task.Node, task.ExitStatus)) |
| 792 | } |
| 793 | |
| 794 | // Introduce delay before refreshing to ensure API consistency |
| 795 | go func() { |
| 796 | // Show refreshing indicator |
| 797 | a.QueueUpdateDraw(func() { |
| 798 | a.header.ShowLoading("Refreshing backup list...") |
| 799 | }) |
| 800 | |
| 801 | time.Sleep(1 * time.Second) |
| 802 | a.QueueUpdateDraw(func() { |
| 803 | a.header.StopLoading() |
| 804 | a.ClearAPICache() |
| 805 | callback() |
| 806 | }) |
| 807 | }() |
| 808 | } else { |
| 809 | // Running update? |
| 810 | callback() |
| 811 | } |
| 812 | }) |
| 813 | }) |
| 814 | } |
no test coverage detected