Skip to content

Commit

Permalink
dataloader syncronizer added (#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
marslanabdulrauf authored Feb 7, 2023
1 parent fc97887 commit 837d420
Showing 1 changed file with 41 additions and 15 deletions.
56 changes: 41 additions & 15 deletions openedx/features/edly/utils.py
Original file line number Diff line number Diff line change
@@ -1,40 +1,40 @@
"""
Utilities for edly app.
"""
from datetime import datetime
import logging
from urllib.parse import urljoin
from datetime import datetime
from urllib.parse import urljoin, urlparse

import jwt
import waffle
from django.conf import settings
from django.contrib.auth.models import Group
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group
from django.contrib.sites.models import Site
from django.core.exceptions import PermissionDenied, ValidationError
from django.db.models import Q
from django.dispatch import receiver
from django.utils.translation import ugettext_lazy as _
from edx_ace import ace
from edx_ace.recipient import Recipient
from xmodule.modulestore.django import modulestore
from edx_rest_api_client.client import EdxRestApiClient
from edx_rest_api_client.exceptions import SlumberBaseException
from six import text_type
from student.message_types import CertificateGeneration
from student.models import CourseAccessRole
from student.roles import CourseInstructorRole, CourseStaffRole, GlobalCourseCreatorRole, GlobalStaff, UserBasedRole
from util.organizations_helpers import get_organizations
from xmodule.modulestore.django import SignalHandler, modulestore

from lms.djangoapps.branding.api import get_privacy_url, get_tos_and_honor_code_url
from openedx.core.djangoapps.catalog.models import CatalogIntegration
from openedx.core.djangoapps.lang_pref import LANGUAGE_KEY
from openedx.core.djangoapps.oauth_dispatch.jwt import create_jwt_for_user
from openedx.core.djangoapps.site_configuration.helpers import get_current_site_configuration
from openedx.core.djangoapps.user_api.preferences import api as preferences_api
from openedx.core.lib.celery.task_utils import emulate_http_request
from openedx.features.edly.constants import ESSENTIALS
from openedx.features.edly.models import EdlyUserProfile, EdlySubOrganization
from student.message_types import CertificateGeneration
from student.models import CourseAccessRole
from student.roles import (
CourseInstructorRole,
CourseStaffRole,
GlobalCourseCreatorRole,
GlobalStaff,
UserBasedRole,
)
from util.organizations_helpers import get_organizations
from openedx.features.edly.models import EdlySubOrganization, EdlyUserProfile

LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -510,6 +510,32 @@ def is_course_org_same_as_site_org(site, course_id):
return False


@receiver(SignalHandler.course_published)
def trigger_dataloader(sender, course_key, **kwargs): # pylint: disable=unused-argument
"""
Run dataloader for specific course on course_published signal.
"""
partner = course_key.org
catalog_integraton = CatalogIntegration.current()
discovery_worker = catalog_integraton.get_service_user()
user_jwt = create_jwt_for_user(discovery_worker)
catalog_api = catalog_integraton.internal_api_url
url_parse = urlparse(catalog_api)
catalog_api = '{}://{}'.format(url_parse.scheme, url_parse.netloc)
discovery_client = EdxRestApiClient(catalog_api, jwt=user_jwt)
try:
res = discovery_client.edly_api.v1.dataloader.post(
{
'partner': partner,
'course_id': text_type(course_key),
'service': 'lms',
}
)
LOGGER.info(res)
except SlumberBaseException as exp:
LOGGER.error(str(exp))


def send_certificate_generation_email(msg, user, site):
"""
Use edx_ace send() to deliver course certificate email based on user and site.
Expand Down

0 comments on commit 837d420

Please sign in to comment.