Fix cache issue in recurring cron job report.

This commit is contained in:
James Cole
2025-06-01 12:24:02 +02:00
parent 5d35edb126
commit ed54a5c9a4
3 changed files with 18 additions and 15 deletions

View File

@@ -28,6 +28,8 @@ use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Jobs\CreateRecurringTransactions; use FireflyIII\Jobs\CreateRecurringTransactions;
use FireflyIII\Models\Configuration; use FireflyIII\Models\Configuration;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Support\Facades\Log;
/** /**
* Class RecurringCronjob * Class RecurringCronjob
@@ -39,34 +41,34 @@ class RecurringCronjob extends AbstractCronjob
*/ */
public function fire(): void public function fire(): void
{ {
app('log')->debug(sprintf('Now in %s', __METHOD__)); Log::debug(sprintf('Now in %s', __METHOD__));
/** @var Configuration $config */ /** @var Configuration $config */
$config = app('fireflyconfig')->get('last_rt_job', 0); $config = FireflyConfig::get('last_rt_job', 0);
$lastTime = (int) $config->data; $lastTime = (int) $config->data;
$diff = Carbon::now()->getTimestamp() - $lastTime; $diff = Carbon::now()->getTimestamp() - $lastTime;
$diffForHumans = today(config('app.timezone'))->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true); $diffForHumans = today(config('app.timezone'))->diffForHumans(Carbon::createFromTimestamp($lastTime), null, true);
if (0 === $lastTime) { if (0 === $lastTime) {
app('log')->info('Recurring transactions cron-job has never fired before.'); Log::info('Recurring transactions cron-job has never fired before.');
} }
// less than half a day ago: // less than half a day ago:
if ($lastTime > 0 && $diff <= 43200) { if ($lastTime > 0 && $diff <= 43200) {
app('log')->info(sprintf('It has been %s since the recurring transactions cron-job has fired.', $diffForHumans)); Log::info(sprintf('It has been "%s" since the recurring transactions cron-job has fired.', $diffForHumans));
if (false === $this->force) { if (false === $this->force) {
app('log')->info('The cron-job will not fire now.'); Log::info('The cron-job will not fire now.');
$this->message = sprintf('It has been %s since the recurring transactions cron-job has fired. It will not fire now.', $diffForHumans); $this->message = sprintf('It has been "%s" since the recurring transactions cron-job has fired. It will not fire now.', $diffForHumans);
$this->jobFired = false; $this->jobFired = false;
$this->jobErrored = false; $this->jobErrored = false;
$this->jobSucceeded = false; $this->jobSucceeded = false;
return; return;
} }
app('log')->info('Execution of the recurring transaction cron-job has been FORCED.'); Log::info('Execution of the recurring transaction cron-job has been FORCED.');
} }
if ($lastTime > 0 && $diff > 43200) { if ($lastTime > 0 && $diff > 43200) {
app('log')->info(sprintf('It has been %s since the recurring transactions cron-job has fired. It will fire now!', $diffForHumans)); Log::info(sprintf('It has been "%s" since the recurring transactions cron-job has fired. It will fire now!', $diffForHumans));
} }
$this->fireRecurring(); $this->fireRecurring();
@@ -76,7 +78,7 @@ class RecurringCronjob extends AbstractCronjob
private function fireRecurring(): void private function fireRecurring(): void
{ {
app('log')->info(sprintf('Will now fire recurring cron job task for date "%s".', $this->date->format('Y-m-d H:i:s'))); Log::info(sprintf('Will now fire recurring cron job task for date "%s".', $this->date->format('Y-m-d H:i:s')));
$job = new CreateRecurringTransactions($this->date); $job = new CreateRecurringTransactions($this->date);
$job->setForce($this->force); $job->setForce($this->force);
@@ -88,8 +90,8 @@ class RecurringCronjob extends AbstractCronjob
$this->jobSucceeded = true; $this->jobSucceeded = true;
$this->message = 'Recurring transactions cron job fired successfully.'; $this->message = 'Recurring transactions cron job fired successfully.';
app('fireflyconfig')->set('last_rt_job', (int) $this->date->format('U')); FireflyConfig::set('last_rt_job', (int) $this->date->format('U'));
app('log')->info(sprintf('Marked the last time this job has run as "%s" (%d)', $this->date->format('Y-m-d H:i:s'), (int) $this->date->format('U'))); Log::info(sprintf('Marked the last time this job has run as "%s" (%d)', $this->date->format('Y-m-d H:i:s'), (int) $this->date->format('U')));
app('log')->info('Done with recurring cron job task.'); Log::info('Done with recurring cron job task.');
} }
} }

View File

@@ -39,7 +39,7 @@ class FireflyConfig
{ {
public function delete(string $name): void public function delete(string $name): void
{ {
$fullName = 'ff-config-'.$name; $fullName = 'ff3-config-'.$name;
if (Cache::has($fullName)) { if (Cache::has($fullName)) {
Cache::forget($fullName); Cache::forget($fullName);
} }
@@ -81,7 +81,7 @@ class FireflyConfig
*/ */
public function get(string $name, mixed $default = null): ?Configuration public function get(string $name, mixed $default = null): ?Configuration
{ {
$fullName = 'ff-config-'.$name; $fullName = 'ff3-config-'.$name;
if (Cache::has($fullName)) { if (Cache::has($fullName)) {
return Cache::get($fullName); return Cache::get($fullName);
} }

View File

@@ -26,6 +26,7 @@ namespace FireflyIII\Support\Http\Controllers;
use Carbon\Carbon; use Carbon\Carbon;
use FireflyIII\Exceptions\FireflyException; use FireflyIII\Exceptions\FireflyException;
use FireflyIII\Support\Facades\FireflyConfig;
use Illuminate\Support\Facades\Log; use Illuminate\Support\Facades\Log;
/** /**
@@ -205,7 +206,7 @@ trait GetConfigurationData
protected function verifyRecurringCronJob(): void protected function verifyRecurringCronJob(): void
{ {
$config = app('fireflyconfig')->get('last_rt_job', 0); $config = FireflyConfig::get('last_rt_job', 0);
$lastTime = (int) $config?->data; $lastTime = (int) $config?->data;
$now = Carbon::now()->getTimestamp(); $now = Carbon::now()->getTimestamp();
app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config?->data, $now)); app('log')->debug(sprintf('verifyRecurringCronJob: last time is %d ("%s"), now is %d', $lastTime, $config?->data, $now));