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

feat: remove content transmission audits without a catalog uuid #1793

Merged
merged 6 commits into from
Jul 24, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 5 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ Change Log

Unreleased
----------

[4.0.3]
--------
feat: remove content transmission audits without a catalog uuid

[4.0.2]
-------
fix: removing items to delete dependency on the catalog service
Expand Down
2 changes: 1 addition & 1 deletion enterprise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@
Your project description goes here.
"""

__version__ = "4.0.2"
__version__ = "4.0.3"

default_app_config = "enterprise.apps.EnterpriseConfig"
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""
Remove content transmission audit records that do not contain a catalog UUID.
"""
import logging

from django.core.management.base import BaseCommand

from integrated_channels.integrated_channel.management.commands import IntegratedChannelCommandMixin
from integrated_channels.integrated_channel.tasks import remove_null_catalog_transmission_audits

LOGGER = logging.getLogger(__name__)


class Command(IntegratedChannelCommandMixin, BaseCommand):
"""
Remove content transmission audit records that do not contain a catalog UUID.
./manage.py lms remove_null_catalog_transmission_audits
"""

def handle(self, *args, **options):
"""
Filter content transmission audit records that do not contain a catalog UUID and remove them.
"""
try:
remove_null_catalog_transmission_audits.delay()
except Exception as exc: # pylint: disable=broad-except
LOGGER.exception(
f'''Failed to remove content transmission audits that do not
contain a catalog UUID. Task failed with exception: {exc}'''
)
25 changes: 25 additions & 0 deletions integrated_channels/integrated_channel/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,31 @@ def _log_batch_task_finish(task_name, channel_code, job_user_id,
))


@shared_task
@set_code_owner_attribute
def remove_null_catalog_transmission_audits():
"""
Task to remove content transmission audit records that do not contain a catalog UUID.
"""
start = time.time()

_log_batch_task_start('remove_null_catalog_transmission_audits', None, None, None)

deleted_null_catalog_uuids = ContentMetadataItemTransmission.objects.filter(
enterprise_customer_catalog_uuid=None
).delete()

duration_seconds = time.time() - start
_log_batch_task_finish(
'remove_null_catalog_transmission_audits',
channel_code=None,
job_user_id=None,
integrated_channel_full_config=None,
duration_seconds=duration_seconds,
extra_message=f"{deleted_null_catalog_uuids[0]} transmission audits with no catalog UUIDs removed"
)


@shared_task
@set_code_owner_attribute
def remove_duplicate_transmission_audits():
Expand Down
32 changes: 32 additions & 0 deletions tests/test_management.py
Original file line number Diff line number Diff line change
Expand Up @@ -2012,3 +2012,35 @@ def test_invalid_audits(self):
assert moodle_config.last_sync_errored_at == old_timestamp
assert moodle_config.last_content_sync_errored_at == old_timestamp
assert moodle_config.last_learner_sync_errored_at is None


@mark.django_db
@ddt.ddt
class TestRemoveNullCatalogTransmissionAuditsManagementCommand(unittest.TestCase, EnterpriseMockMixin):
"""
Test the ``remove_null_catalog_transmission_audits`` management command.
"""
def setUp(self):
self.enterprise_customer_1 = factories.EnterpriseCustomerFactory(
name='Wonka Factory',
)
self.enterprise_customer_2 = factories.EnterpriseCustomerFactory(
name='Hershey LLC',
)
factories.ContentMetadataItemTransmissionFactory(
enterprise_customer=self.enterprise_customer_1,
enterprise_customer_catalog_uuid=None
)
factories.ContentMetadataItemTransmissionFactory(
enterprise_customer=self.enterprise_customer_2,
enterprise_customer_catalog_uuid="d9efab41-5e09-4094-977a-96313b3dca08"
)
super().setUp()

def test_normal_run(self):
assert ContentMetadataItemTransmission.objects.all().count() == 2
call_command('remove_null_catalog_transmission_audits')
assert ContentMetadataItemTransmission.objects.all().count() == 1
assert ContentMetadataItemTransmission.objects.filter(
enterprise_customer_catalog_uuid=None
).count() == 0
Loading