JReviews Queue Add-on

From JReviews Documentation
Revision as of 14:06, 29 January 2018 by Jreviews (Talk | contribs) (Installing Supervisor)

Jump to: navigation, search


Overview

The Queue Add-on changes the way certain events execute on your site so they are executed asynchronously and run independently of the main program flow. They are executed in a non-blocking scheme, allowing the main action to continue processing without unnecessary delays. This not only improves the user experience due to faster processing, but it also means that an error in one of the events won't affect the main program flow. Lets put all of this into a practical example:

When a listing, review or media is submitted there are many actions that take place, other than saving the review in the database. These include:

  • Sending one or more e-mail notifications
  • Posting the review to Twitter
  • Posting the review to Facebook
  • Posting the review to the JomSocial or EasySocial streams (Joomla)
  • Triggering native Joomla or WordPress events

These events are all executed in series, one after the other, and it can amount to a substantial delay. Even if one of these events results in error, then the review for submission could hang and the rest of the events will not be executed.

Requirements

  • JReviews v3 or higher
  • A process monitor that can execute queued events. We recommend using Supervisor, a process monitor for Linux that will automatically restart the queue process if it fails.

Add-on Configuration

In the Add-on configuration you can choose the types of events (emails, Twitter, Facebook, etc.) that you want to executed through the queue vs having them run directly with the main program flow.

One of the additional advantages of running certain events through the queue is that it is possible to introduce an additional delay before the event is executed. For example, when a listing is submitted and photos are uploaded for this listing right after, if the listing will be posted to Twitter or Facebook, by introducing a delay to these events, the listing can already have a published photo by the time it gets posted to Twitter and Facebook.

Supervisor Configuration

Installing Supervisor

To install Supervisor on Ubuntu, you may use the following command:

sudo apt-get install supervisor

Configuring Supervisor

Supervisor configuration files are typically stored in the /etc/supervisor/conf.d directory. Within this directory, you may create any number of configuration files that instruct supervisor how your processes should be monitored. For example, let's create a jreviews-worker.conf file that starts and monitors the JReviews queue.

[program:jreviews-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /path/to/queue-addon/worker-many.php
autostart=true
autorestart=true
numprocs=8
redirect_stderr=true
stderr_logfile=/path/to/folder/below/public/jreviews-worker.err.log
stdout_logfile=/path/to/folder/below/public/jreviews-worker.out.log

In this example, the numprocs directive will instruct Supervisor to run 8 processes and monitor all of them, automatically restarting them if they fail.

On some hosts, like DigitalOcean, you may need to specify the PHP version to use in the command.

command=php7.0-sp /path/to/queue-addon/worker-many.php /path/to/queue-addon/worker-many.php

The path to the queue Add-on is as follows:

Joomla

/path/to/site/components/com_jreviews_addons/worker-many.php

WordPress

/path/to/site/wp-content/plugins/jreviews_addons/worker-many.php


Starting Supervisor

Once the configuration file has been created, you may update the Supervisor configuration and start the processes using the following commands:

sudo supervisorctl reread
 
sudo supervisorctl update
 
sudo supervisorctl start

For more information on Supervisor, consult the Supervisor documentation

Failed Jobs

When an event is added to the queue, we call this a job. If a job fails, it will be attempted later. If the maximum number of attempts is exceeded, the job will be moved to the failed queue table. The Add-on provides a convinient way to look at the current Queue Jobs and the Failed Jobs through the admin dashboard.