This guide provides a detailed process to configure Mautic to use Doctrine for managing email queues, implementing cron jobs to automate the process, and ensuring efficient and stable email delivery.
local.php
Filelocal.php
File
local.php
file is typically found in the app/config
directory of your Mautic installation.local.php
file:<?php
return array(
// Other Mautic configuration settings...
'messenger' => [
'default_bus' => 'messenger.bus.default',
'transports' => [
'doctrine' => [
'dsn' => 'doctrine://default?table_name=messenger_messages',
],
],
],
// Additional configuration settings...
);
/path/to/mautic/var/lock/consume_mautic.sh
:#!/bin/bash
# Path to the lock file
LOCKFILE="/path/to/mautic/var/lock/consume_mautic.lock"
LOGFILE="/path/to/mautic/var/logs/mautic_consume_detailed.log"
# Define the lock file timeout (9 minutes = 540 seconds)
LOCKFILE_TIMEOUT=540
# Function to log messages
log() {
echo "$(date '+%Y-%m-%d %H:%M:%S') - $1" >> "$LOGFILE"
}
log "Script started."
# Check if the lock file exists
if [ -e $LOCKFILE ]; then
LOCKFILE_AGE=$(($(date +%s) - $(stat -c %Y $LOCKFILE)))
if [ $LOCKFILE_AGE -ge $LOCKFILE_TIMEOUT ]; then
log "Lock file is older than $LOCKFILE_TIMEOUT seconds. Removing stale lock file."
rm -f $LOCKFILE
else
log "Process is already running. Exiting."
exit 1
fi
fi
# Create the lock file
touch $LOCKFILE
log "Lock file created."
# Run the messenger:consume command for emails with increased verbosity and log the output
log "Starting to consume messages..."
/usr/bin/php /path/to/mautic/bin/console messenger:consume email --limit=60 --time-limit=480 --memory-limit=128M -vvv >> "$LOGFILE" 2>&1
log "Finished consuming messages."
# Remove the lock file when done
rm -f $LOCKFILE
log "Lock file removed."
log "Script finished."
chmod +x /path/to/mautic/var/lock/consume_mautic.sh
crontab -e
*/10 * * * * /path/to/mautic/var/lock/consume_mautic.sh >> /path/to/mautic/var/logs/mautic_consume.log 2>&1
This schedules the script to run every 10 minutes, logging output to mautic_consume.log
.
mkdir -p /path/to/mautic/var/lock
mkdir -p /path/to/mautic/var/logs
/path/to/mautic/var/lock/consume_mautic.sh
tail -f /path/to/mautic/var/logs/mautic_consume.log
messenger_messages
table can fill up quickly, especially under heavy load. Regularly monitor disk space and consider implementing automated cleanup routines to prevent crashes.-vvv
flag in the script provides detailed logs that can help diagnose issues.messenger_messages
table fills up, consider adjusting cron timings or migrating to a different transport.
Article Number: 184
Author: Aug 20, 2024
Last Updated: Aug 20, 2024
Author: Renato Carabelli [[email protected]]
Online URL: https://kb.mautic.org/article/configuring-doctrine-for-email-queue-management-in-mautic-with-cron-jobs.html