2022-01-10 11:02:18 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
|
|
|
import time
|
|
|
|
|
|
|
|
from django.utils import timezone
|
|
|
|
|
|
|
|
from common.utils.timezone import local_now_display
|
|
|
|
from .handlers import AccountBackupHandler
|
|
|
|
|
|
|
|
|
2022-11-03 08:57:34 +00:00
|
|
|
class AccountBackupManager:
|
2022-01-10 11:02:18 +00:00
|
|
|
def __init__(self, execution):
|
|
|
|
self.execution = execution
|
|
|
|
self.date_start = timezone.now()
|
|
|
|
self.time_start = time.time()
|
|
|
|
self.date_end = None
|
|
|
|
self.time_end = None
|
|
|
|
self.timedelta = 0
|
|
|
|
|
|
|
|
def do_run(self):
|
|
|
|
execution = self.execution
|
2023-08-01 10:17:02 +00:00
|
|
|
print('\n\033[33m# 账号备份计划正在执行\033[0m')
|
2022-01-10 11:02:18 +00:00
|
|
|
handler = AccountBackupHandler(execution)
|
|
|
|
handler.run()
|
|
|
|
|
|
|
|
def pre_run(self):
|
|
|
|
self.execution.date_start = self.date_start
|
|
|
|
self.execution.save()
|
|
|
|
|
|
|
|
def post_run(self):
|
|
|
|
self.time_end = time.time()
|
|
|
|
self.date_end = timezone.now()
|
|
|
|
|
2023-08-01 10:17:02 +00:00
|
|
|
print('\n\n' + '-' * 80)
|
|
|
|
print('计划执行结束 {}\n'.format(local_now_display()))
|
2022-01-10 11:02:18 +00:00
|
|
|
self.timedelta = self.time_end - self.time_start
|
2023-08-01 10:17:02 +00:00
|
|
|
print('用时: {}s'.format(self.timedelta))
|
2022-01-10 11:02:18 +00:00
|
|
|
self.execution.timedelta = self.timedelta
|
|
|
|
self.execution.save()
|
|
|
|
|
|
|
|
def run(self):
|
|
|
|
self.pre_run()
|
|
|
|
self.do_run()
|
|
|
|
self.post_run()
|