How to setup Live Helper Chat cronjob?

Default cronjob setup

LHC uses cronjob for background chats assignment and maintenence tasks.

php cron.php -s site_admin -c cron/workflow

This cronjob does the following things.

  • Automatic chat's transfer workflow
  • Executes unanswered chats workflow
  • Executes automatic chat's purging/closing
  • Executes round robin workflow

Should be run every minute or even more frequent if you want live chat auto assignment workflow to feel like live. See performance tweaks

Shell script example to run workflow every 5 seconds

Cronjob example

* * * * * cd /home/lhc/cronjobs && ./workflow.sh >> /dev/null 2>&1

Shell script. Set your paths.

#!/bin/sh
fileCron='/home/lhc/cronjobs/running-workflow'
for i in {1..12}
do
if [ ! -f $fileCron ];
then
touch $fileCron;
cd /home/lhc/lhc-official/lhc_web && /usr/bin/php cron.php -s site_admin -c cron/workflow >> workflow.log
echo "$(tail -1000 workflow.log)" > workflow.log
rm -f $fileCron;
else
if [ `stat --format=%Y $fileCron` -le $(( `date +%s` - 30 )) ]; then
rm -f $fileCron;
fi
echo "Already running"
fi
sleep 5
done

Chat archive cronjob setup

php cron.php -s site_admin -c cron/archive

This cronjob does automatic chat's archiving

Department availability cronjob

This cronjob tracks department availability. It's collected data is used to generate department availability statistic data.

php cron.php -s site_admin -c cron/departament-availability

Should be run every minute.

Chats anonymization

If you have setup chat's anonymization you should run this cronjob.

php cron.php -s site_admin -c cron/encrypt

Should be run every 12 hours or so.

Notifications

php cron.php -s site_admin -c cron/notifications
  1. Send notification to those chat's where visitor has unread message from operator.
  2. Last sync stopped 4 - 5 minutes. (It sends last unread message. Like we don't know what message was seen by visitor exactly and which not)
  3. We should log within chat. Last notified message id. Also mark chat as notification was send
  4. If operator sends another message. We reset flag about notification. So cronjobs sends notification only for new messages. Since we have logged it.
  5. Notification should be send for all chats. Not only active one where visitor did not read. But also for closed one.

Should be run every 5 minutes or so.

Files maintenance

It automatically deletes files based on files maintenance settings.

php cron.php -s site_admin -c cron/util/maintain_files

Should be run every few hours or so.

Database maintenance

It makes sense time from tim run this script to optimize users departments table. As this table get's a lot of updates.

php cron.php -s site_admin -c cron/util/maintain_database

Should be run every few hours or so.

How to add cronjob in extension?

Yes, extensions supports cronjobs. What you have to do is:

php cron.php -s site_admin -e customstatus -c cron/customcron

Example file in github which will executed.

Last updated on by Çağlar Yeşilyurt