chg: [CLI] Initialize BackgroundJobsTool just when required

pull/7975/head
Jakub Onderka 2021-11-20 14:49:58 +01:00
parent b322bd55c5
commit cc1908a7fd
1 changed files with 15 additions and 7 deletions

View File

@ -79,8 +79,7 @@ class ServerShell extends AppShell
));
foreach ($servers as $serverId => $serverName) {
$backgroundJobId = $this->Server->getBackgroundJobsTool()->enqueue(
$backgroundJobId = $this->getBackgroundJobsTool()->enqueue(
BackgroundJobsTool::DEFAULT_QUEUE,
BackgroundJobsTool::CMD_SERVER,
[
@ -189,8 +188,7 @@ class ServerShell extends AppShell
));
foreach ($servers as $serverId => $serverName) {
$jobId = $this->Server->getBackgroundJobsTool()->enqueue(
$jobId = $this->getBackgroundJobsTool()->enqueue(
BackgroundJobsTool::DEFAULT_QUEUE,
BackgroundJobsTool::CMD_SERVER,
[
@ -309,8 +307,7 @@ class ServerShell extends AppShell
));
foreach ($servers as $serverId => $serverName) {
$jobId = $this->Server->getBackgroundJobsTool()->enqueue(
$jobId = $this->getBackgroundJobsTool()->enqueue(
BackgroundJobsTool::DEFAULT_QUEUE,
BackgroundJobsTool::CMD_SERVER,
[
@ -320,7 +317,7 @@ class ServerShell extends AppShell
]
);
$this->out("Enqueued cacheServer from {$serverName} server as job $jobId");
$this->out("Enqueued cacheServer from $serverName server as job $jobId");
}
}
@ -605,4 +602,15 @@ class ServerShell extends AppShell
}
return $server;
}
/**
* @return BackgroundJobsTool
*/
private function getBackgroundJobsTool()
{
if (!$this->BackgroundJobsTool) {
$this->BackgroundJobsTool = new BackgroundJobsTool(Configure::read('SimpleBackgroundJobs'));
}
return $this->BackgroundJobsTool;
}
}