* add locking to the cli job so it only starts once
This commit is contained in:
parent
c7a2e68a82
commit
25ff60b34b
@ -12,19 +12,25 @@ use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class UpdatePageCachesCommand extends Command
|
||||
{
|
||||
const LOCK_FILE = 'data/update-caches-cron.lock';
|
||||
|
||||
/** @var JiraCollectorService */
|
||||
private $jiraCollectorService;
|
||||
|
||||
/** @var TeamService */
|
||||
private $teamService;
|
||||
|
||||
public function __construct(JiraCollectorService $jiraCollectorService, TeamService $teamService)
|
||||
public function __construct(JiraCollectorService $jiraCollectorService,
|
||||
TeamService $teamService)
|
||||
{
|
||||
$this->jiraCollectorService = $jiraCollectorService;
|
||||
$this->teamService = $teamService;
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
/**
|
||||
* Configure the command
|
||||
*/
|
||||
protected function configure()
|
||||
{
|
||||
$this->setName('cache:update')
|
||||
@ -39,6 +45,11 @@ class UpdatePageCachesCommand extends Command
|
||||
*/
|
||||
protected function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if ($this->isLocked()) {
|
||||
$output->writeln("Lock file exists, not starting.");
|
||||
return;
|
||||
}
|
||||
$this->createLock();
|
||||
$teams = $this->teamService->listTeams();
|
||||
foreach ($teams as $team) {
|
||||
set_time_limit(30);
|
||||
@ -47,5 +58,33 @@ class UpdatePageCachesCommand extends Command
|
||||
}
|
||||
$this->jiraCollectorService->getTeamWatchedIssues($team->getId(), true);
|
||||
}
|
||||
$this->releaseLock();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create the lock file
|
||||
* @return bool
|
||||
*/
|
||||
private function createLock(): bool
|
||||
{
|
||||
return touch(self::LOCK_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the lock file
|
||||
* @return bool
|
||||
*/
|
||||
private function releaseLock(): bool
|
||||
{
|
||||
return unlink(self::LOCK_FILE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if lock file exists
|
||||
* @return bool
|
||||
*/
|
||||
private function isLocked(): bool
|
||||
{
|
||||
return file_exists(self::LOCK_FILE);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user