feat: cron-triggered cleanup command for XML-dumps
This commit is contained in:
@@ -3,6 +3,9 @@ zenstruck_schedule:
|
|||||||
|
|
||||||
mailer:
|
mailer:
|
||||||
service: mailer
|
service: mailer
|
||||||
|
default_to: [email protected]
|
||||||
|
default_from: [email protected]
|
||||||
|
subject_prefix: "[MyE&P-Team]"
|
||||||
|
|
||||||
schedule_extensions:
|
schedule_extensions:
|
||||||
email_on_failure:
|
email_on_failure:
|
||||||
@@ -28,3 +31,7 @@ zenstruck_schedule:
|
|||||||
- task: messenger:consume async -t 60
|
- task: messenger:consume async -t 60
|
||||||
frequency: '*/5 * * * *'
|
frequency: '*/5 * * * *'
|
||||||
description: "Starts messenger queue"
|
description: "Starts messenger queue"
|
||||||
|
|
||||||
|
- task: app:cleanup:xml-dumps
|
||||||
|
frequency: "0 1 * * *"
|
||||||
|
description: "Removes outdated XML dumps of requests/responses to BPN API for debugging"
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Command;
|
||||||
|
|
||||||
|
use League\Flysystem\FilesystemException;
|
||||||
|
use League\Flysystem\FilesystemOperator;
|
||||||
|
use League\Flysystem\StorageAttributes;
|
||||||
|
use Psr\Log\LoggerInterface;
|
||||||
|
use Symfony\Component\Console\Attribute\AsCommand;
|
||||||
|
use Symfony\Component\Console\Command\Command;
|
||||||
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
use Symfony\Component\Console\Style\SymfonyStyle;
|
||||||
|
|
||||||
|
#[AsCommand(
|
||||||
|
name: 'app:cleanup:xml-dumps',
|
||||||
|
description: 'Removes XML dumps of BPN requests/responses older than 3 days'
|
||||||
|
)]
|
||||||
|
class CleanupXMLDumpsCommand extends Command
|
||||||
|
{
|
||||||
|
public function __construct(
|
||||||
|
private readonly FilesystemOperator $xmlDump,
|
||||||
|
private readonly LoggerInterface $logger,
|
||||||
|
) {
|
||||||
|
parent::__construct();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function execute(InputInterface $input, OutputInterface $output): int
|
||||||
|
{
|
||||||
|
$io = new SymfonyStyle($input, $output);
|
||||||
|
|
||||||
|
// we look for files older than 1 week
|
||||||
|
$maxDate = (new \DateTimeImmutable())->modify('-3 days')->getTimestamp();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$files = $this
|
||||||
|
->xmlDump
|
||||||
|
->listContents('.')
|
||||||
|
->filter(fn (StorageAttributes $attributes) => $attributes->isFile() && $attributes->lastModified() < $maxDate)
|
||||||
|
->map(fn (StorageAttributes $attributes) => $attributes->path())
|
||||||
|
->toArray();
|
||||||
|
} catch (FilesystemException $e) {
|
||||||
|
$io->error($e->getMessage());
|
||||||
|
|
||||||
|
return Command::FAILURE;
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach ($files as $file) {
|
||||||
|
$this->xmlDump->delete($file);
|
||||||
|
}
|
||||||
|
|
||||||
|
$message = 'Removed '.count($files).' outdated XML dumps';
|
||||||
|
|
||||||
|
$this->logger->info($message);
|
||||||
|
$io->success($message);
|
||||||
|
|
||||||
|
return Command::SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user