Skip to content

Commit

Permalink
CU-2cr86jm - Move retry_ipfs_backup to thread when start up.
Browse files Browse the repository at this point in the history
  • Loading branch information
fred-yu-2013 authored and stiartsly committed Mar 28, 2022
1 parent bff8a77 commit c366cee
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 9 deletions.
10 changes: 5 additions & 5 deletions hive/main/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,18 @@
logging.getLogger().level = logging.INFO


class RefreshVaultStorageUsage(threading.Thread):
class RefreshVaultStorageUsageThread(threading.Thread):
def __init__(self):
super().__init__()

def run(self):
# Reset the storage size of all vaults when initialize.
try:
logging.info(f'[RefreshVaultStorageUsage] Start init all vaults usage.')
logging.info(f'[RefreshVaultStorageUsageThread] Start init all vaults usage.')
count_vault_storage_job()
logging.info(f'[RefreshVaultStorageUsage] Init vault usage successfully')
logging.info(f'[RefreshVaultStorageUsageThread] Init vault usage successfully')
except Exception as e:
logging.error(f'[RefreshVaultStorageUsage] Init vault usage failed {str(e)}')
logging.error(f'[RefreshVaultStorageUsageThread] Init vault usage failed {str(e)}')


def init_app(app, mode):
Expand Down Expand Up @@ -55,5 +55,5 @@ def init_app(app, mode):
else:
scheduler.scheduler_init(app, paused=False)

RefreshVaultStorageUsage().start()
RefreshVaultStorageUsageThread().start()
logging.getLogger('v1_init').info('leave init_app')
2 changes: 0 additions & 2 deletions src/modules/ipfs/ipfs_backup_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,8 +272,6 @@ def retry_backup_request(self, user_did):
req = self.get_request(user_did)
if not req or req.get(BACKUP_REQUEST_STATE) != BACKUP_REQUEST_STATE_INPROGRESS:
return
elif req.get(BACKUP_REQUEST_STATE) != BACKUP_REQUEST_STATE_INPROGRESS:
return
logging.info(f"[IpfsBackupClient] Found uncompleted request({req.get(USR_DID)}), retry.")
if req.get(BACKUP_REQUEST_ACTION) == BACKUP_REQUEST_ACTION_BACKUP:
BackupExecutor(user_did, self, req, start_delay=30).start()
Expand Down
3 changes: 2 additions & 1 deletion src/utils/http_exception.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class NotFoundException(HiveException):
FILE_NOT_FOUND = 6
ORDER_NOT_FOUND = 7
RECEIPT_NOT_FOUND = 8
APPLICATION_NOT_FOUND = 9

def __init__(self, internal_code=VAULT_NOT_FOUND, msg='The vault can not be found or is not activate.'):
super().__init__(404, internal_code, msg)
Expand All @@ -121,7 +122,7 @@ def __init__(self, msg='The backup service can not be found.'):

class ApplicationNotFoundException(NotFoundException):
def __init__(self, msg='The application of the user can not be found.'):
super().__init__(internal_code=NotFoundException.BACKUP_NOT_FOUND, msg=msg)
super().__init__(internal_code=NotFoundException.APPLICATION_NOT_FOUND, msg=msg)


class ScriptNotFoundException(NotFoundException):
Expand Down
17 changes: 16 additions & 1 deletion src/view/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
import logging
import threading

from src.utils.db_client import cli
from src.utils.scheduler import scheduler_init
Expand All @@ -12,11 +13,25 @@ def retry_ipfs_backup():
2. handle all backup request in the backup node.
"""
user_dids = cli.get_all_user_dids()
logging.info(f'[retry_ipfs_backup] get {len(user_dids)} users')
for user_did in user_dids:
backup.backup_client.retry_backup_request(user_did)
backup.backup_server.retry_backup_request(user_did)


class RetryIpfsBackupThread(threading.Thread):
def __init__(self):
super().__init__()

def run(self):
try:
logging.info(f'[RetryIpfsBackupThread] enter')
retry_ipfs_backup()
logging.info(f'[RetryIpfsBackupThread] leave')
except Exception as e:
logging.error(f'[RetryIpfsBackupThread] error {str(e)}')


def init_app(app):
logging.getLogger('v2_init').info('enter init_app')
about.init_app(app)
Expand All @@ -29,6 +44,6 @@ def init_app(app):
backup.init_app(app)
provider.init_app(app)

retry_ipfs_backup()
RetryIpfsBackupThread().start()
scheduler_init(app)
logging.getLogger('v2_init').info('leave init_app')

0 comments on commit c366cee

Please sign in to comment.