Timezone por DI
This commit is contained in:
@ -15,7 +15,8 @@ return [
|
||||
Incoviba\Command\BaseLoop::class => function(ContainerInterface $container) {
|
||||
return new Incoviba\Command\BaseLoop(
|
||||
$container->get('LoopLogger'),
|
||||
$container->get(Incoviba\Service\Schedule::class)
|
||||
$container->get(Incoviba\Service\Schedule::class),
|
||||
$container->get(DateTimeZone::class),
|
||||
);
|
||||
}
|
||||
];
|
||||
|
@ -15,12 +15,12 @@ use Incoviba\Service\Schedule;
|
||||
)]
|
||||
class BaseLoop extends Console\Command\Command
|
||||
{
|
||||
public function __construct(protected LoggerInterface $logger, protected Schedule $scheduleService, ?string $name = null)
|
||||
public function __construct(protected LoggerInterface $logger, protected Schedule $scheduleService,
|
||||
protected DateTimeZone $timezone,
|
||||
?string $name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
$this->timezone = new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago');
|
||||
}
|
||||
protected DateTimeZone $timezone;
|
||||
|
||||
public function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
|
||||
{
|
||||
@ -59,6 +59,7 @@ class BaseLoop extends Console\Command\Command
|
||||
$command = $this->getApplication()->find($commandName);
|
||||
} catch (Console\Exception\CommandNotFoundException $exception) {
|
||||
$this->logger->warning($exception);
|
||||
return self::FAILURE;
|
||||
}
|
||||
|
||||
$cmd = new Console\Input\ArrayInput([
|
||||
|
@ -16,7 +16,9 @@ use Incoviba\Common\Alias\Command;
|
||||
class Queue extends Command
|
||||
{
|
||||
public function __construct(ClientInterface $client, LoggerInterface $logger,
|
||||
protected Job $jobService, ?string $name = null)
|
||||
protected Job $jobService,
|
||||
protected DateTimeZone $timezone,
|
||||
?string $name = null)
|
||||
{
|
||||
parent::__construct($client, $logger, $name);
|
||||
}
|
||||
@ -25,7 +27,7 @@ class Queue extends Command
|
||||
{
|
||||
$this->logger->debug("Running {$this->getName()}");
|
||||
$io = new Console\Style\SymfonyStyle($input, $output);
|
||||
$now = new DateTimeImmutable('now', new DateTimeZone($_ENV['TZ'] ?? 'America/Santiago'));
|
||||
$now = new DateTimeImmutable('now', $this->timezone);
|
||||
$io->title("[{$now->format('Y-m-d H:i:s e')}] Running Queue...");
|
||||
|
||||
$jobs = $this->getJobs($output);
|
||||
|
Reference in New Issue
Block a user