Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

temp: added standard logging and removed celery logging #32577

Merged
merged 3 commits into from
Jun 26, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 21 additions & 8 deletions common/djangoapps/entitlements/tasks.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
This file contains celery tasks for entitlements-related functionality.
"""
import logging
from celery import shared_task
from celery.utils.log import get_task_logger
from django.conf import settings # lint-amnesty, pylint: disable=unused-import
Expand All @@ -10,6 +11,7 @@
from common.djangoapps.entitlements.models import CourseEntitlement, CourseEntitlementSupportDetail

LOGGER = get_task_logger(__name__)
log = logging.getLogger(__name__)

# Maximum number of retries before giving up on awarding credentials.
# For reference, 11 retries with exponential backoff yields a maximum waiting
Expand Down Expand Up @@ -91,19 +93,24 @@ def expire_and_create_entitlements(self, entitlement_ids, support_username):
first_entitlement_id = entitlement_ids[0]
last_entitlement_id = entitlement_ids[-1]

LOGGER.info(
'Running task expire_and_create_entitlements over %d entitlements from id %d to id %d',
log.info(
'Running task expire_and_create_entitlements over %d entitlements from id %d to id %d, task id :%s',
len(entitlement_ids),
first_entitlement_id,
last_entitlement_id,
self.request.id
)

try:
for entitlement_id in entitlement_ids:
entitlement = CourseEntitlement.objects.get(id=entitlement_id)
LOGGER.info('Started expiring entitlement with id %d', entitlement.id)
log.info('Started expiring entitlement with id %d, task id :%s',
entitlement.id,
self.request.id)
entitlement.expire_entitlement()
LOGGER.info('Expired entitlement with id %d as expiration period has reached', entitlement.id)
log.info('Expired entitlement with id %d as expiration period has reached, task id :%s',
entitlement.id,
self.request.id)
support_detail = {
'action': 'EXPIRE',
'comments': 'REV-3574',
Expand All @@ -127,13 +134,19 @@ def expire_and_create_entitlements(self, entitlement_ids, support_username):
'support_user': support_user,
}
CourseEntitlementSupportDetail.objects.create(**support_detail)
LOGGER.info(
'created new entitlement with id %d corresponding to above expired entitlement with id %d',
log.info(
'created new entitlement with id %d corresponding to above expired entitlement'
'with id %d, task id :%s ',
new_entitlement.id,
entitlement.id,
self.request.id
)

except Exception as exc: # pylint: disable=broad-except
LOGGER.exception('Failed to expire entitlements that reached their expiration period')
log.exception('Failed to expire entitlements that reached their expiration period, task id :%s',
self.request.id)

LOGGER.info('Successfully completed the task expire_and_create_entitlements after examining %d entries', len(entitlement_ids)) # lint-amnesty, pylint: disable=line-too-long
log.info('Successfully completed the task expire_and_create_entitlements after examining'
'%d entries, task id :%s',
len(entitlement_ids),
self.request.id)