Skip to content
Snippets Groups Projects
Commit b076f503 authored by Jared Hancock's avatar Jared Hancock
Browse files

autocron: Release agent session before running

The PHP session system will hold a lock on the session until it is released.
It is important to release the session before performing long-running tasks
so that further requests from the agent are not locked.
parent 282c0fb5
No related branches found
No related tags found
No related merge requests found
......@@ -39,14 +39,25 @@ ob_start(); //Keep the image output clean. Hide our dirt.
$sec=time()-$_SESSION['lastcroncall'];
$caller = $thisstaff->getUserName();
if($sec>180 && $ost && !$ost->isUpgradePending()): //user can call cron once every 3 minutes.
// Agent can call cron once every 3 minutes.
if ($sec < 180 || !$ost || $ost->isUpgradePending())
ob_end_clean();
require_once(INCLUDE_DIR.'class.cron.php');
$thisstaff = null; //Clear staff obj to avoid false credit internal notes & auto-assignment
Cron::TicketMonitor(); //Age tickets: We're going to age tickets regardless of cron settings.
// Clear staff obj to avoid false credit internal notes & auto-assignment
$thisstaff = null;
// Release the session to prevent locking a future request while this is
// running
$_SESSION['lastcroncall'] = time();
session_write_close();
// Age tickets: We're going to age tickets regardless of cron settings.
Cron::TicketMonitor();
// Run file purging about every 30 minutes
if (mt_rand(1, 9) == 4)
// Run file purging about every 20 cron runs (1h40 on a five minute cron)
if (mt_rand(1, 20) == 4)
Cron::CleanOrphanedFiles();
if($cfg && $cfg->isAutoCronEnabled()) { //ONLY fetch tickets if autocron is enabled!
......@@ -57,7 +68,5 @@ if($cfg && $cfg->isAutoCronEnabled()) { //ONLY fetch tickets if autocron is enab
$data = array('autocron'=>true);
Signal::send('cron', $data);
$_SESSION['lastcroncall']=time();
endif;
ob_end_clean();
?>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment