Skip to content

Commit aeab3fa

Browse files
committed
expire shared drive function
1 parent 5dede1b commit aeab3fa

File tree

2 files changed

+12
-18
lines changed

2 files changed

+12
-18
lines changed

endorsement/dao/shared_drive.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,15 @@ def sync_quota_from_subscription(drive_id):
8484
raise SharedDriveRecordNotFound(drive_id)
8585

8686

87-
def expire_shared_drives(gracetime, lifetime):
88-
"""
89-
Expire shared drives that have exceeded their lifetime.
90-
"""
91-
for drive in shared_drives_to_expire(gracetime, lifetime):
92-
shared_drive_lifecycle_expired(drive)
87+
def expire_shared_drive(shared_drive_record):
88+
try:
89+
shared_drive_lifecycle_expired(shared_drive_record.shared_drive)
90+
shared_drive_record.datetime_deleted = timezone.now()
91+
shared_drive_record.save()
92+
except DataFailureException as ex:
93+
logger.error(
94+
"Cannot expire drive "
95+
f"{shared_drive_record.shared_drive.drive_id} : {ex}")
9396

9497

9598
def shared_drive_lifecycle_expired(shared_drive):

endorsement/management/commands/expire_shared_drives.py

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
# SPDX-License-Identifier: Apache-2.0
33

44
from django.core.management.base import BaseCommand
5-
from django.utils import timezone
65
from restclients_core.exceptions import DataFailureException
76
from endorsement.policy.shared_drive import SharedDrivePolicy
8-
from endorsement.dao.shared_drive import shared_drive_lifecycle_expired
7+
from endorsement.dao.shared_drive import (
8+
shared_drive_lifecycle_expired, expire_shared_drive)
99
import csv
1010
import logging
1111

@@ -52,16 +52,7 @@ def handle(self, *args, **options):
5252
f'"{record.shared_drive.drive_name}"')
5353

5454
if actually_mark_for_deletion:
55-
self.expire_drive(record)
56-
57-
def expire_drive(self, record):
58-
try:
59-
shared_drive_lifecycle_expired(record.shared_drive)
60-
record.datetime_deleted = timezone.now()
61-
record.save()
62-
except DataFailureException as ex:
63-
logger.error(
64-
"Cannot expire drive {record.shared_drive.drive_id} : {ex}")
55+
expire_shared_drive(record)
6556

6657
def _record_csv(self, record):
6758
self.drive_writer.writerow([

0 commit comments

Comments
 (0)