From a91feab3b65c1cb0473d9849503e4dd433456356 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 26 Nov 2022 12:10:18 +1100 Subject: [PATCH] Smooth out cron jobs --- app/Console/Kernel.php | 2 +- app/Jobs/Ninja/SystemMaintenance.php | 4 ---- app/Jobs/Util/ReminderJob.php | 21 +++++++++++---------- 3 files changed, 12 insertions(+), 15 deletions(-) diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index fb7fa77b3ec1..cd578176e0c2 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -84,7 +84,7 @@ class Kernel extends ConsoleKernel $schedule->job(new TaskScheduler())->dailyAt('06:50')->withoutOverlapping(); /* Performs system maintenance such as pruning the backup table */ - $schedule->job(new SystemMaintenance)->weekly()->withoutOverlapping(); + $schedule->job(new SystemMaintenance)->sundays()->at('02:30')->withoutOverlapping(); /* Pulls in bank transactions from third party services */ $schedule->job(new BankTransactionSync)->dailyAt('04:10')->withoutOverlapping(); diff --git a/app/Jobs/Ninja/SystemMaintenance.php b/app/Jobs/Ninja/SystemMaintenance.php index de3571304c08..01219ce4b9cc 100644 --- a/app/Jobs/Ninja/SystemMaintenance.php +++ b/app/Jobs/Ninja/SystemMaintenance.php @@ -49,10 +49,6 @@ class SystemMaintenance implements ShouldQueue nlog('Starting System Maintenance'); - if (Ninja::isHosted()) { - return; - } - $delete_pdf_days = config('ninja.maintenance.delete_pdfs'); nlog("Number of days to keep PDFs {$delete_pdf_days}"); diff --git a/app/Jobs/Util/ReminderJob.php b/app/Jobs/Util/ReminderJob.php index 64e6faf13cef..6a2f55d754a8 100644 --- a/app/Jobs/Util/ReminderJob.php +++ b/app/Jobs/Util/ReminderJob.php @@ -87,7 +87,7 @@ class ReminderJob implements ShouldQueue $query->where('is_disabled', 0); }) ->with('invitations')->cursor()->each(function ($invoice) { - if ($invoice->isPayable()) { + if ($invoice->refresh() && $invoice->isPayable()) { //Attempts to prevent duplicates from sending if($invoice->reminder_last_sent && Carbon::parse($invoice->reminder_last_sent)->startOfDay()->eq(now()->startOfDay())){ @@ -97,9 +97,8 @@ class ReminderJob implements ShouldQueue $reminder_template = $invoice->calculateTemplate('invoice'); nlog("reminder template = {$reminder_template}"); - $invoice = $this->calcLateFee($invoice, $reminder_template); $invoice->service()->touchReminder($reminder_template)->save(); - $invoice->service()->touchPdf(true); + $invoice = $this->calcLateFee($invoice, $reminder_template); //20-04-2022 fixes for endless reminders - generic template naming was wrong $enabled_reminder = 'enable_'.$reminder_template; @@ -220,16 +219,18 @@ class ReminderJob implements ShouldQueue $invoice->client->service()->updateBalance($invoice->balance - $temp_invoice_balance); $invoice->ledger()->updateInvoiceBalance($invoice->balance - $temp_invoice_balance, "Late Fee Adjustment for invoice {$invoice->number}"); - $transaction = [ - 'invoice' => $invoice->transaction_event(), - 'payment' => [], - 'client' => $invoice->client->transaction_event(), - 'credit' => [], - 'metadata' => ['setLateFee'], - ]; + // $transaction = [ + // 'invoice' => $invoice->transaction_event(), + // 'payment' => [], + // 'client' => $invoice->client->transaction_event(), + // 'credit' => [], + // 'metadata' => ['setLateFee'], + // ]; // TransactionLog::dispatch(TransactionEvent::CLIENT_STATUS, $transaction, $invoice->company->db); + $invoice->service()->touchPdf(true); + return $invoice; } }