Skip to content

Commit

Permalink
WR #452436: Prevent excimer processors from doubling up partial saves.
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Den Dulk committed Feb 4, 2025
1 parent 7ac5964 commit 3a678b6
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
13 changes: 13 additions & 0 deletions classes/cron_processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ class cron_processor implements processor {
/** @var int */
protected $samplems;

/** @var bool */
protected static $isinsideoninterval = false;

/**
* Initialises the processor
*
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -135,6 +146,8 @@ public function on_interval(manager $manager) {
// So it needs to be saved each loop.
$this->sampletime = $sampletime;
}

self::$isinsideoninterval = false;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions classes/web_processor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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);

Expand All @@ -134,5 +144,7 @@ public function process(manager $manager, bool $isfinal) {
}
$this->profile->save_record();
}

self::$isinsideprocess = false;
}
}

0 comments on commit 3a678b6

Please sign in to comment.