jumpserver/apps/accounts/automations/backup_account/manager.py

37 lines
1.2 KiB
Python
Raw Normal View History

2022-01-10 11:02:18 +00:00
# -*- coding: utf-8 -*-
#
import time
from django.utils.translation import gettext_lazy as _
2022-01-10 11:02:18 +00:00
2024-11-18 11:06:04 +00:00
from assets.automations.base.manager import BaseManager
from common.db.utils import safe_db_connection
2022-01-10 11:02:18 +00:00
from common.utils.timezone import local_now_display
from .handlers import AccountBackupHandler
2024-11-18 11:06:04 +00:00
class AccountBackupManager(BaseManager):
2022-01-10 11:02:18 +00:00
def do_run(self):
execution = self.execution
account_backup_execution_being_executed = _('The account backup plan is being executed')
print(f'\n\033[33m# {account_backup_execution_being_executed}\033[0m')
2022-01-10 11:02:18 +00:00
handler = AccountBackupHandler(execution)
handler.run()
2024-11-18 11:06:04 +00:00
def send_report_if_need(self):
pass
def update_execution(self):
timedelta = int(time.time() - self.time_start)
self.execution.timedelta = timedelta
2022-01-10 11:02:18 +00:00
2024-11-18 11:06:04 +00:00
with safe_db_connection():
self.execution.save(update_fields=['timedelta', ])
2022-01-10 11:02:18 +00:00
2024-11-18 11:06:04 +00:00
def print_summary(self):
print('\n\n' + '-' * 80)
plan_execution_end = _('Plan execution end')
print('{} {}\n'.format(plan_execution_end, local_now_display()))
2024-11-25 11:17:53 +00:00
time_cost = _('Duration')
2024-11-18 11:06:04 +00:00
print('{}: {}s'.format(time_cost, self.duration))