Skip to content

Commit f993030

Browse files
committed
Made sure tasks aren't executed concurrently
1 parent e45c37f commit f993030

File tree

1 file changed

+17
-2
lines changed

1 file changed

+17
-2
lines changed

Tasks.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ public function schedule()
6767
*/
6868
public function auditSite(int $idSite)
6969
{
70-
if ($this->hasTaskStartedToday($idSite)) {
71-
Log::info('Performance Audit task for site ' . $idSite . ' has been already started today');
70+
if ($this->hasAnyTaskStartedToday()) {
71+
Log::info('Performance Audit tasks have been already started today');
7272
return;
7373
}
7474
Log::info('Performance Audit task for site ' . $idSite . ' will be started now');
@@ -89,6 +89,21 @@ public function auditSite(int $idSite)
8989
Log::info('Performance Audit task for site ' . $idSite . ' has finished');
9090
}
9191

92+
/**
93+
* Check if any task has started today.
94+
*
95+
* @return bool
96+
* @throws Exception
97+
*/
98+
private function hasAnyTaskStartedToday()
99+
{
100+
$tasksStartedToday = array_map(function($site) {
101+
return $this->hasTaskStartedToday((int) $site['idsite']);
102+
}, Site::getSites());
103+
104+
return in_array(true, $tasksStartedToday);
105+
}
106+
92107
/**
93108
* Check if this task has started today.
94109
*

0 commit comments

Comments
 (0)