From c30e0f77689c3e5c7b219076b04c5743e354b797 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Wed, 25 Oct 2023 17:57:35 -0400 Subject: [PATCH] Remove Lock files older than 10 Mins aka 600 Secs and log it for Cron Email Parser and Cron Mail Queue --- cron_mail_queue.php | 10 +++++++++- cron_ticket_email_parser.php | 11 +++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/cron_mail_queue.php b/cron_mail_queue.php index e8ab6069..af9cdb01 100644 --- a/cron_mail_queue.php +++ b/cron_mail_queue.php @@ -13,7 +13,15 @@ $lock_file_path = "{$temp_dir}/itflow_mail_queue_{$installation_id}.lock"; // Check for lock file to prevent concurrent script runs if (file_exists($lock_file_path)) { - exit("Script is already running. Exiting."); + $file_age = time() - filemtime($lock_file_path); + + // If file is older than 10 minutes (600 seconds), delete and continue + if ($file_age > 600) { + unlink($lock_file_path); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron-Mail-Queue', log_action = 'Delete', log_description = 'Cron Mail Queuer detected a lock file was present but was over 10 minutes old so it removed it.'"); + } else { + exit("Script is already running. Exiting."); + } } // Create a lock file diff --git a/cron_ticket_email_parser.php b/cron_ticket_email_parser.php index 13f73b27..fa6a8ccd 100644 --- a/cron_ticket_email_parser.php +++ b/cron_ticket_email_parser.php @@ -20,7 +20,6 @@ require_once "config.php"; require_once "functions.php"; - // Get system temp directory $temp_dir = sys_get_temp_dir(); @@ -29,7 +28,15 @@ $lock_file_path = "{$temp_dir}/itflow_email_parser_{$installation_id}.lock"; // Check for lock file to prevent concurrent script runs if (file_exists($lock_file_path)) { - exit("Script is already running. Exiting."); + $file_age = time() - filemtime($lock_file_path); + + // If file is older than 10 minutes (600 seconds), delete and continue + if ($file_age > 600) { + unlink($lock_file_path); + mysqli_query($mysqli, "INSERT INTO logs SET log_type = 'Cron-Email-Parser', log_action = 'Delete', log_description = 'Cron Email Parser detected a lock file was present but was over 10 minutes old so it removed it'"); + } else { + exit("Script is already running. Exiting."); + } } // Create a lock file