Skip to content
Lou Wolford edited this page Apr 27, 2016 · 12 revisions

Using Celery

Retrieving Activity Metadata

It is stated in the xAPI spec that, "If an Activity IRI is an IRL, an LRS SHOULD attempt to GET that IRL, and include in HTTP headers: "Accept: application/json, /". This SHOULD be done as soon as practical after the LRS first encounters the Activity id. Upon loading JSON which is a valid Activity Definition from an IRL used as an Activity id, an LRS SHOULD incorporate the loaded definition into its internal definition for that Activity, while preserving names or definitions not included in the loaded definition."

The ADL LRS will now retrieve activity metadata, void statements, and check LRS hooks via celery. This speeds up the processing of incoming statements, especially those that are in large batches, and gives the client a faster response.

Voiding Statements

In case batch statements don't come in the correct order when voiding statements, the LRS will wait until all statements from that batch are stored, then will start worker processes to attempt to void the statements that were specified instead of returning a 404 error when trying to void statements sequentially.

Setup

The LRS will be using Celery as an asynchronous task queue and RabbitMQ as its message broker to retrieve the activity metadata. This will be running completely independent of Django. The libraries required for this should already be installed in your environment (amqp and celery) from the requirements.txt document.

RabbitMQ Setup

For details and more in-depth documentation, visit the celery docs.

  1. admin:~$ sudo apt-get install rabbitmq-server
  2. admin:~$ sudo rabbitmqctl add_user <username_for_rabbitmq> <password_for_rabbitmq>
  3. admin:~$ sudo rabbitmqctl add_vhost <vhost_name>
  4. admin:~$ sudo rabbitmqctl set_permissions -p <vhost_name> <username_for_rabbitmq> ".*" ".*" ".*"

Celery Setup

For details and more in-depth documentation, visit the celery docs.

  1. Configure /path/to/ADL_LRS/lrs/celery.py

    app = Celery('lrs',
             broker='amqp://<username_for_rabbitmq>:<password_for_rabbitmq>@localhost:5672/<vhost_name>',
             include=['lrs.tasks'])
    
  2. Configure /path/to/ADL_LRS/celeryd.conf

    command=/path/to/env/bin/celery worker -A lrs --loglevel=INFO
    
    directory=/path/to/ADL_LRS
    
    stdout_logfile=/path/to/logs/celery/celery-worker.log
    stderr_logfile=/path/to/logs/celery/celery-worker-errors.log
    
    
    
  3. Configure /path/to/ADL_LRS/supervisord.conf

    logfile=/path/to/logs/supervisord/supervisord.log
    childlogdir=/path/to/logs/supervisord/
    
  4. Create upstart script in /etc/init/ (our file will be called celerylrs.conf). You will need to use sudo for admin privileges.

    description    "supervisor for lrs-celery"
    start on runlevel    [2345]
    stop on runlevel    [!2345]
    
    respawn
    
    setuid <Name of system user LRS is running under>
    chdir /path/to/ADL_LRS
    exec /path/to/env/bin/supervisord --nodaemon
    

    You can stop start/stop the celery tasks by typing sudo {start|stop|restart} celerylrs

    NOTE: If you're using Ubuntu 15+ it uses systemd instead of upstart by default. Follow these instructions for a systemd script

    Create systemd script in /lib/systemd/system/ (our file will be called celerylrs.service). You will need to use sudo for admin privileges.

    [Unit]
    Description=Supervisor to run celery for the LRS
    
    [Service]
    User=<Name of system user LRS is running under>
    WorkingDirectory=/path/to/ADL_LRS
    ExecStart=/path/to/env/bin/supervisord --nodaemon
    Restart=on-failure
    
    [Install]
    WantedBy=multi-user.target
    

    You can stop start/stop the celery tasks by typing sudo systemctl {start|stop|restart} celerylrs

Clone this wiki locally