From 0b2a7c02c362ad12beabe5d5a0039e8b91108db5 Mon Sep 17 00:00:00 2001 From: Manu <3916435+m3nu@users.noreply.github.com> Date: Mon, 15 Nov 2021 15:18:11 +0400 Subject: [PATCH] Remove jobs before deleting profile (#1107) --- src/vorta/log.py | 1 - src/vorta/scheduler.py | 10 ++++++---- src/vorta/tray_menu.py | 5 +++-- src/vorta/views/main_window.py | 5 +++-- 4 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/vorta/log.py b/src/vorta/log.py index 3e613cac..2fae6faf 100644 --- a/src/vorta/log.py +++ b/src/vorta/log.py @@ -17,7 +17,6 @@ def init_logger(background=False): logger.setLevel(logging.DEBUG) logging.getLogger('peewee').setLevel(logging.INFO) - logging.getLogger('apscheduler').setLevel(logging.INFO) logging.getLogger('PyQt5').setLevel(logging.INFO) # create logging format diff --git a/src/vorta/scheduler.py b/src/vorta/scheduler.py index 58d7e377..23012c46 100644 --- a/src/vorta/scheduler.py +++ b/src/vorta/scheduler.py @@ -53,8 +53,7 @@ def set_timer_for_profile(self, profile_id): # First stop and remove any existing timer for this profile self.lock.acquire() if profile_id in self.timers: - self.timers[profile_id]['qtt'].stop() - del self.timers[profile_id] + self.remove_job(profile_id) # If no repo is set or only manual backups, just return without # replacing the job we removed above. @@ -121,7 +120,6 @@ def reload_all_timers(self): for profile in BackupProfileModel.select(): self.set_timer_for_profile(profile.id) - @property def next_job(self): next_job = now = dt.now() next_profile = None @@ -180,7 +178,7 @@ def create_backup(self, profile_id): def notify(self, result): notifier = VortaNotifications.pick() profile_name = result['params']['profile_name'] - profile_id = result['params']['profile'] + profile_id = result['params']['profile'].id if result['returncode'] in [0, 1]: notifier.deliver(self.tr('Vorta Backup'), @@ -229,3 +227,7 @@ def post_backup_tasks(self, profile_id): self.app.jobs_manager.add_job(job) logger.info('Finished background task for profile %s', profile.name) + + def remove_job(self, profile_id): + self.timers[profile_id]['qtt'].stop() + del self.timers[profile_id] diff --git a/src/vorta/tray_menu.py b/src/vorta/tray_menu.py index fdc23626..afe7a517 100644 --- a/src/vorta/tray_menu.py +++ b/src/vorta/tray_menu.py @@ -44,7 +44,8 @@ def on_user_click(self): menu.addSeparator() - status = menu.addAction(self.app.scheduler.next_job) + next_task_time = self.app.scheduler.next_job() + status = menu.addAction(next_task_time) status.setEnabled(False) if self.app.jobs_manager.is_worker_running(): @@ -52,7 +53,7 @@ def on_user_click(self): cancel_action = menu.addAction(self.tr('Cancel Backup')) cancel_action.triggered.connect(self.app.backup_cancelled_event.emit) else: - status.setText(self.tr('Next Task: %s') % self.app.scheduler.next_job) + status.setText(self.tr('Next Task: %s') % next_task_time) profiles = BackupProfileModel.select() if profiles.count() > 1: profile_menu = menu.addMenu(self.tr('Backup Now')) diff --git a/src/vorta/views/main_window.py b/src/vorta/views/main_window.py index bf685f54..f60a3094 100644 --- a/src/vorta/views/main_window.py +++ b/src/vorta/views/main_window.py @@ -157,15 +157,16 @@ def profile_rename_action(self): def profile_delete_action(self): if self.profileSelector.count() > 1: - to_delete = BackupProfileModel.get(id=self.profileSelector.currentData()) + to_delete_id = self.profileSelector.currentData() + to_delete = BackupProfileModel.get(id=to_delete_id) - # TODO: Remove pending background jobs msg = self.tr("Are you sure you want to delete profile '{}'?".format(to_delete.name)) reply = QMessageBox.question(self, self.tr("Confirm deletion"), msg, QMessageBox.Yes | QMessageBox.No, QMessageBox.No) if reply == QMessageBox.Yes: to_delete.delete_instance(recursive=True) + self.app.scheduler.remove_job(to_delete_id) # Remove pending jobs self.profileSelector.removeItem(self.profileSelector.currentIndex()) self.profile_select_action(0)