Add cron job to download transaction currencies from Azure (if enabled by user).

This commit is contained in:
James Cole
2022-06-09 17:47:01 +02:00
parent de3376c966
commit beed44f065
8 changed files with 362 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Support\Cronjobs\AutoBudgetCronjob;
use FireflyIII\Support\Cronjobs\BillWarningCronjob;
use FireflyIII\Support\Cronjobs\ExchangeRatesCronjob;
use FireflyIII\Support\Cronjobs\RecurringCronjob;
use Illuminate\Console\Command;
use InvalidArgumentException;
@@ -69,6 +70,19 @@ class Cron extends Command
}
$force = (bool) $this->option('force');
/*
* Fire recurring transaction cron job.
*/
if (true === config('cer.enabled')) {
try {
$this->exchangeRatesCronJob($force, $date);
} catch (FireflyException $e) {
Log::error($e->getMessage());
Log::error($e->getTraceAsString());
$this->error($e->getMessage());
}
}
/*
* Fire recurring transaction cron job.
*/
@@ -190,4 +204,32 @@ class Cron extends Command
}
}
/**
* @param bool $force
* @param Carbon|null $date
* @throws FireflyException
*/
private function exchangeRatesCronJob(bool $force, ?Carbon $date): void
{
$exchangeRates = new ExchangeRatesCronjob;
$exchangeRates->setForce($force);
// set date in cron job:
if (null !== $date) {
$exchangeRates->setDate($date);
}
$exchangeRates->fire();
if ($exchangeRates->jobErrored) {
$this->error(sprintf('Error in "exchange rates" cron: %s', $exchangeRates->message));
}
if ($exchangeRates->jobFired) {
$this->error(sprintf('"Exchange rates" cron fired: %s', $exchangeRates->message));
}
if ($exchangeRates->jobSucceeded) {
$this->error(sprintf('"Exchange rates" cron ran with success: %s', $exchangeRates->message));
}
}
}