Change blobuploadcleanupworker to use a data interface
This commit is contained in:
parent
b2053829f9
commit
bdab367285
5 changed files with 93 additions and 21 deletions
|
@ -4,8 +4,8 @@ import logging.config
|
|||
from datetime import timedelta
|
||||
|
||||
from app import app, storage
|
||||
from data.database import UseThenDisconnect, BlobUpload
|
||||
from data import model
|
||||
from data.database import UseThenDisconnect
|
||||
from workers.blobuploadcleanupworker.models_pre_oci import pre_oci_model as model
|
||||
from workers.worker import Worker
|
||||
from util.log import logfile_path
|
||||
|
||||
|
@ -26,7 +26,7 @@ class BlobUploadCleanupWorker(Worker):
|
|||
while True:
|
||||
# Find all blob uploads older than the threshold (typically a week) and delete them.
|
||||
with UseThenDisconnect(app.config):
|
||||
stale_upload = model.blob.get_stale_blob_upload(DELETION_DATE_THRESHOLD)
|
||||
stale_upload = model.get_stale_blob_upload(DELETION_DATE_THRESHOLD)
|
||||
if stale_upload is None:
|
||||
logger.debug('No additional stale blob uploads found')
|
||||
return
|
||||
|
@ -34,7 +34,7 @@ class BlobUploadCleanupWorker(Worker):
|
|||
# Remove the stale upload from storage.
|
||||
logger.debug('Removing stale blob upload %s', stale_upload.uuid)
|
||||
try:
|
||||
storage.cancel_chunked_upload([stale_upload.location.name], stale_upload.uuid,
|
||||
storage.cancel_chunked_upload([stale_upload.location_name], stale_upload.uuid,
|
||||
stale_upload.storage_metadata)
|
||||
except Exception as ex:
|
||||
logger.debug('Got error when trying to cancel chunked upload %s: %s', stale_upload.uuid,
|
||||
|
@ -42,10 +42,7 @@ class BlobUploadCleanupWorker(Worker):
|
|||
|
||||
# Delete the stale upload's row.
|
||||
with UseThenDisconnect(app.config):
|
||||
try:
|
||||
stale_upload.delete_instance()
|
||||
except BlobUpload.DoesNotExist:
|
||||
continue
|
||||
model.delete_blob_upload(stale_upload)
|
||||
|
||||
logger.debug('Removed stale blob upload %s', stale_upload.uuid)
|
||||
|
||||
|
|
Reference in a new issue