Consuming course_published event

11 views
Skip to first unread message

Todd Lichty

unread,
Jun 24, 2019, 10:42:49 AM6/24/19
to General Open edX discussion
I would like to create a handler for the course_published event. 

Based on the comments in the SignalHandler class:

class SignalHandler(object):
    """
    This class is to allow the modulestores to emit signals that can be caught
    by other parts of the Django application. If your app needs to do something
    every time a course is published (e.g. search indexing), you can listen for
    that event and kick off a celery task when it happens.
    To listen for a signal, do the following::
        from django.dispatch import receiver
        from celery.task import task
        from xmodule.modulestore.django import modulestore, SignalHandler
        @receiver(SignalHandler.course_published)
        def listen_for_course_publish(sender, course_key, **kwargs):
            do_my_expensive_update.delay(course_key)
        @task()
        def do_my_expensive_update(course_key):
            # ...
    Things to note:
    1. We receive using the Django Signals mechanism.
    2. The sender is going to be the class of the modulestore sending it.
    3. The names of your handler function's parameters *must* be "sender" and "course_key".
    4. Always have **kwargs in your signal handler, as new things may be added.
    5. The thing that listens for the signal lives in process, but should do
       almost no work. Its main job is to kick off the celery task that will
       do the actual work.
    """

I understand what the code should look like. What I don't understand is where this code should go. Do I need to create a new django app and install it or is there a simpler way?

Thanks
Reply all
Reply to author
Forward
0 new messages