add cron
This commit is contained in:
@@ -16,21 +16,34 @@ class MeilisearchIndexCron
|
|||||||
|
|
||||||
public function __invoke(): void
|
public function __invoke(): void
|
||||||
{
|
{
|
||||||
|
$this->log('Cron START');
|
||||||
|
|
||||||
// Contao initialisieren
|
// Contao initialisieren
|
||||||
$this->framework->initialize();
|
$this->framework->initialize();
|
||||||
|
$this->log('Contao framework initialized');
|
||||||
|
|
||||||
// 1) Contao Crawl
|
// 1) Contao Crawl
|
||||||
|
$this->log('Step 1 START: contao:crawl');
|
||||||
$this->runConsole('contao:crawl');
|
$this->runConsole('contao:crawl');
|
||||||
|
$this->log('Step 1 END: contao:crawl');
|
||||||
|
|
||||||
// 2) Cleanup (24h Grace)
|
// 2) Cleanup (24h Grace)
|
||||||
$this->runConsole('meilisearch:files:cleanup');
|
$this->log('Step 2 START: meilisearch:files:cleanup');
|
||||||
|
$this->runConsole('meilisearch:files:cleanup --grace=86400');
|
||||||
|
$this->log('Step 2 END: meilisearch:files:cleanup');
|
||||||
|
|
||||||
// 3) Meilisearch Index
|
// 3) Meilisearch Index
|
||||||
|
$this->log('Step 3 START: MeilisearchIndexService::run()');
|
||||||
$this->indexService->run();
|
$this->indexService->run();
|
||||||
|
$this->log('Step 3 END: MeilisearchIndexService::run()');
|
||||||
|
|
||||||
|
$this->log('Cron END');
|
||||||
}
|
}
|
||||||
|
|
||||||
private function runConsole(string $command): void
|
private function runConsole(string $command): void
|
||||||
{
|
{
|
||||||
|
$start = microtime(true);
|
||||||
|
|
||||||
$process = new Process([
|
$process = new Process([
|
||||||
'php',
|
'php',
|
||||||
$this->projectDir . '/vendor/bin/contao-console',
|
$this->projectDir . '/vendor/bin/contao-console',
|
||||||
@@ -39,5 +52,28 @@ class MeilisearchIndexCron
|
|||||||
|
|
||||||
$process->setTimeout(null);
|
$process->setTimeout(null);
|
||||||
$process->run();
|
$process->run();
|
||||||
|
|
||||||
|
$duration = round(microtime(true) - $start, 2);
|
||||||
|
|
||||||
|
$this->log(sprintf(
|
||||||
|
'Command "%s" finished (exit=%d, time=%ss)',
|
||||||
|
$command,
|
||||||
|
$process->getExitCode(),
|
||||||
|
$duration
|
||||||
|
));
|
||||||
|
|
||||||
|
if (!$process->isSuccessful()) {
|
||||||
|
$this->log('STDERR: ' . trim($process->getErrorOutput()));
|
||||||
|
} else {
|
||||||
|
$out = trim($process->getOutput());
|
||||||
|
if ($out !== '') {
|
||||||
|
$this->log('STDOUT: ' . $out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private function log(string $message): void
|
||||||
|
{
|
||||||
|
error_log('[MeilisearchCron] ' . $message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user