mirror of
https://github.com/chenasraf/nextcloud-autocurrency.git
synced 2026-05-17 17:28:06 +00:00
34 lines
1.1 KiB
PHP
34 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace OCA\AutoCurrency\Cron;
|
|
|
|
use OCA\AutoCurrency\AppInfo;
|
|
use OCA\AutoCurrency\Service\FetchCurrenciesService;
|
|
use OCP\AppFramework\Utility\ITimeFactory;
|
|
use OCP\BackgroundJob\TimedJob;
|
|
use OCP\IAppConfig;
|
|
use Psr\Log\LoggerInterface;
|
|
|
|
class FetchCurrenciesJob extends TimedJob {
|
|
private FetchCurrenciesService $service;
|
|
private LoggerInterface $logger;
|
|
private IAppConfig $config;
|
|
|
|
public function __construct(ITimeFactory $time, FetchCurrenciesService $service, LoggerInterface $logger, IAppConfig $config) {
|
|
parent::__construct($time);
|
|
$this->service = $service;
|
|
$this->logger = $logger;
|
|
$this->config = $config;
|
|
|
|
$interval = $this->config->getValueInt(AppInfo\Application::APP_ID, 'cron_interval', 24);
|
|
$this->setInterval(3600 * $interval);
|
|
$this->setTimeSensitivity(\OCP\BackgroundJob\IJob::TIME_INSENSITIVE);
|
|
$this->logger->info('FetchCurrenciesJob initialized');
|
|
}
|
|
|
|
protected function run($arguments): void {
|
|
$this->logger->info('Running cron job for FetchCurrenciesTask - args: ' . json_encode($arguments));
|
|
$this->service->fetchCurrencyRates();
|
|
}
|
|
}
|