From 3a678b693df079ed6b376af8fac49d9bd0a5a3d4 Mon Sep 17 00:00:00 2001 From: Jason Den Dulk Date: Tue, 4 Feb 2025 15:17:47 +1100 Subject: [PATCH] WR #452436: Prevent excimer processors from doubling up partial saves. --- classes/cron_processor.php | 13 +++++++++++++ classes/web_processor.php | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/classes/cron_processor.php b/classes/cron_processor.php index 59b66ab..afe2267 100644 --- a/classes/cron_processor.php +++ b/classes/cron_processor.php @@ -42,6 +42,9 @@ class cron_processor implements processor { /** @var int */ protected $samplems; + /** @var bool */ + protected static $isinsideoninterval = false; + /** * Initialises the processor * @@ -93,6 +96,14 @@ public function get_min_duration(): float { * @param manager $manager */ public function on_interval(manager $manager) { + // We want to prevent doubling up of processing, so skip if an existing process is still executing. + // The profile logs will be kept and processed the next time. + if (self::$isinsideoninterval) { + debugging('tool_excimer: starting cron_processor::on_interval when previous call has not yet finished'); + return; + } + self::$isinsideoninterval = true; + $profiler = $manager->get_profiler(); $log = $profiler->flush(); $memoryusage = memory_get_usage(); // Record and set initial memory usage at this point. @@ -135,6 +146,8 @@ public function on_interval(manager $manager) { // So it needs to be saved each loop. $this->sampletime = $sampletime; } + + self::$isinsideoninterval = false; } /** diff --git a/classes/web_processor.php b/classes/web_processor.php index 2925f3e..49ad27b 100644 --- a/classes/web_processor.php +++ b/classes/web_processor.php @@ -42,6 +42,8 @@ class web_processor implements processor { protected $samplems; /** @var bool */ protected $partialsave; + /** @var bool */ + protected static $isinsideprocess = false; /** * Construct the web processor. @@ -111,6 +113,14 @@ public function get_min_duration(): float { * @throws \dml_exception */ public function process(manager $manager, bool $isfinal) { + // We want to prevent doubling up of processing, so skip if an existing process is still executing. + // The profile logs will be kept and processed the next time. + if (self::$isinsideprocess) { + debugging('tool_excimer: starting web_processor::process when previous process has not yet finished'); + return; + } + self::$isinsideprocess = true; + $log = $manager->get_profiler()->flush(); $this->sampleset->add_many_samples($log); @@ -134,5 +144,7 @@ public function process(manager $manager, bool $isfinal) { } $this->profile->save_record(); } + + self::$isinsideprocess = false; } }