feat: update logic and modified code
This commit is contained in:
committed by
Phillip Shiu
parent
4d4f1cd1b5
commit
b88a34d3f5
@@ -19,14 +19,8 @@ class Command(BaseCommand):
|
||||
"""
|
||||
Management command for expiring old entitlements and issuing new one against them.
|
||||
|
||||
Most entitlements get expired as the user interacts with the platform,
|
||||
because the LMS checks as it goes. This command is to expire entitlements older than one year and issue new one
|
||||
against them. But if the learner has not logged in
|
||||
for a while, we still want to reap these old entitlements. So this command
|
||||
should be run every now and then (probably daily) to expire old
|
||||
entitlements.
|
||||
|
||||
The command's goal is to pass a narrow subset of entitlements to an
|
||||
The command's goal is expire a set of entitlements depending on the --count argument passed to an
|
||||
idempotent Celery task for further (parallelized) processing.
|
||||
"""
|
||||
help = dedent(__doc__).strip()
|
||||
@@ -69,9 +63,9 @@ class Command(BaseCommand):
|
||||
)
|
||||
return
|
||||
|
||||
for batch_num in range(int(num_batches)):
|
||||
start = batch_num * batch_size + 1 # ids are 1-based, so add 1
|
||||
end = min(start + batch_size, total + 1)
|
||||
expire_and_create_entitlements.delay(start, end, logid=str(batch_num))
|
||||
while total > 0:
|
||||
total = total - batch_size
|
||||
no_of_entitlements = min(total, batch_size)
|
||||
expire_and_create_entitlements.delay(no_of_entitlements)
|
||||
|
||||
logger.info('Done. Successfully enqueued %d tasks.', num_batches)
|
||||
|
||||
@@ -76,7 +76,7 @@ def expire_old_entitlements(self, start, end, logid='...'):
|
||||
|
||||
@shared_task(bind=True, ignore_result=True)
|
||||
@set_code_owner_attribute
|
||||
def expire_and_create_entitlements(self):
|
||||
def expire_and_create_entitlements(self, no_of_entitlements):
|
||||
"""
|
||||
This task is designed to be called to process and expire bundle of entitlements
|
||||
that are older than one year on in exceptional case 18 months.
|
||||
@@ -101,11 +101,8 @@ def expire_and_create_entitlements(self):
|
||||
|
||||
|
||||
try:
|
||||
for entitlement in entitlements:
|
||||
# This property request will update the expiration if necessary as
|
||||
# a side effect. We could manually call update_expired_at(), but
|
||||
# let's use the same API the rest of the LMS does, to mimic normal
|
||||
# usage and allow the update call to be an internal detail.
|
||||
for entitlement in entitlements[:no_of_entitlements]:
|
||||
|
||||
entitlement.expire_entitlement()
|
||||
LOGGER.info('Expired entitlement with id %d ', entitlement.id)
|
||||
entitlement.pk = None
|
||||
|
||||
Reference in New Issue
Block a user