Skip to content

Commit

Permalink
don't send CrontabJobEvent.manual_backup_created if backup is aborted
Browse files Browse the repository at this point in the history
  • Loading branch information
Fallen-Breath committed Oct 22, 2024
1 parent 200e820 commit 7ee7cfd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
4 changes: 2 additions & 2 deletions prime_backup/mcdr/command/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,8 @@ def cmd_db_migrate_hash_method(self, source: CommandSource, context: CommandCont
self.task_manager.add_task(MigrateHashMethodTask(source, new_hash_method))

def cmd_make(self, source: CommandSource, context: CommandContext):
def callback(_, err):
if err is None:
def callback(backup_id: Optional[int], err: Optional[Exception]):
if err is None and backup_id is not None:
self.crontab_manager.send_event(CrontabJobEvent.manual_backup_created)

comment = context.get('comment', '')
Expand Down
11 changes: 6 additions & 5 deletions prime_backup/mcdr/task/backup/create_backup_task.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from prime_backup.utils.timer import Timer


class CreateBackupTask(HeavyTask[None]):
class CreateBackupTask(HeavyTask[Optional[int]]):
def __init__(self, source: CommandSource, comment: str, operator: Optional[Operator] = None):
super().__init__(source)
self.comment = comment
Expand All @@ -28,7 +28,7 @@ def id(self) -> str:
def is_abort_able(self) -> bool:
return self.__waiting_world_save

def run(self):
def run(self) -> Optional[int]:
self.broadcast(self.tr('start'))

cmds = self.config.server.commands
Expand All @@ -47,14 +47,14 @@ def run(self):
self.__waiting_world_save = False
if self.aborted_event.is_set():
self.broadcast(self.get_aborted_text())
return
return None
if not ok:
self.broadcast(self.tr('abort.save_wait_time_out').set_color(RColor.red))
return
return None
cost_save_wait = timer.get_and_restart()
if self.plugin_unloaded_event.is_set():
self.broadcast(self.tr('abort.unloaded').set_color(RColor.red))
return
return None

action = CreateBackupAction(self.operator, self.comment)
backup = action.run()
Expand All @@ -75,6 +75,7 @@ def run(self):
TextComponents.backup_size(backup),
TextComponents.blob_list_summary_store_size(bls),
))
return backup.id
finally:
if applied_auto_save_off and len(cmds.auto_save_on) > 0:
self.server.execute(cmds.auto_save_on)
Expand Down

0 comments on commit 7ee7cfd

Please sign in to comment.