1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-13 22:54:25 +01:00

Clean up for scheduled jobs

This commit is contained in:
David Bomba 2023-05-04 09:42:42 +10:00
parent 20e833e430
commit 53b522ea5d
8 changed files with 44 additions and 22 deletions

View File

@ -11,10 +11,11 @@
namespace App\Jobs\Cron; namespace App\Jobs\Cron;
use App\Libraries\MultiDB;
use App\Models\Invoice; use App\Models\Invoice;
use Illuminate\Foundation\Bus\Dispatchable; use App\Libraries\MultiDB;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Bus\Dispatchable;
class AutoBillCron class AutoBillCron
{ {
@ -45,6 +46,8 @@ class AutoBillCron
/* Get all invoices where the send date is less than NOW + 30 minutes() */ /* Get all invoices where the send date is less than NOW + 30 minutes() */
info('Performing Autobilling '.Carbon::now()->format('Y-m-d h:i:s')); info('Performing Autobilling '.Carbon::now()->format('Y-m-d h:i:s'));
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
$auto_bill_partial_invoices = Invoice::whereDate('partial_due_date', '<=', now()) $auto_bill_partial_invoices = Invoice::whereDate('partial_due_date', '<=', now())
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])

View File

@ -11,13 +11,14 @@
namespace App\Jobs\Cron; namespace App\Jobs\Cron;
use App\Factory\RecurringExpenseToExpenseFactory;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use Illuminate\Support\Carbon;
use App\Models\RecurringExpense; use App\Models\RecurringExpense;
use App\Models\RecurringInvoice; use App\Models\RecurringInvoice;
use Illuminate\Support\Facades\Auth;
use App\Utils\Traits\GeneratesCounter; use App\Utils\Traits\GeneratesCounter;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Carbon; use App\Factory\RecurringExpenseToExpenseFactory;
class RecurringExpensesCron class RecurringExpensesCron
{ {
@ -45,6 +46,8 @@ class RecurringExpensesCron
/* Get all expenses where the send date is less than NOW + 30 minutes() */ /* Get all expenses where the send date is less than NOW + 30 minutes() */
nlog('Sending recurring expenses '.Carbon::now()->format('Y-m-d h:i:s')); nlog('Sending recurring expenses '.Carbon::now()->format('Y-m-d h:i:s'));
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
$recurring_expenses = RecurringExpense::where('next_send_date', '<=', now()->toDateTimeString()) $recurring_expenses = RecurringExpense::where('next_send_date', '<=', now()->toDateTimeString())
->whereNotNull('next_send_date') ->whereNotNull('next_send_date')

View File

@ -11,12 +11,13 @@
namespace App\Jobs\Cron; namespace App\Jobs\Cron;
use App\Jobs\RecurringInvoice\SendRecurring;
use App\Libraries\MultiDB;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\RecurringInvoice; use App\Libraries\MultiDB;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Carbon; use Illuminate\Support\Carbon;
use App\Models\RecurringInvoice;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Bus\Dispatchable;
use App\Jobs\RecurringInvoice\SendRecurring;
class RecurringInvoicesCron class RecurringInvoicesCron
{ {
@ -43,6 +44,8 @@ class RecurringInvoicesCron
/* Get all invoices where the send date is less than NOW + 30 minutes() */ /* Get all invoices where the send date is less than NOW + 30 minutes() */
$start = Carbon::now()->format('Y-m-d h:i:s'); $start = Carbon::now()->format('Y-m-d h:i:s');
nlog('Sending recurring invoices '.$start); nlog('Sending recurring invoices '.$start);
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
$recurring_invoices = RecurringInvoice::where('status_id', RecurringInvoice::STATUS_ACTIVE) $recurring_invoices = RecurringInvoice::where('status_id', RecurringInvoice::STATUS_ACTIVE)

View File

@ -11,8 +11,9 @@
namespace App\Jobs\Cron; namespace App\Jobs\Cron;
use App\Libraries\MultiDB;
use App\Models\Invoice; use App\Models\Invoice;
use App\Libraries\MultiDB;
use Illuminate\Support\Facades\Auth;
use App\Utils\Traits\SubscriptionHooker; use App\Utils\Traits\SubscriptionHooker;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
@ -39,6 +40,8 @@ class SubscriptionCron
{ {
nlog('Subscription Cron'); nlog('Subscription Cron');
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
$invoices = Invoice::where('is_deleted', 0) $invoices = Invoice::where('is_deleted', 0)
->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL]) ->whereIn('status_id', [Invoice::STATUS_SENT, Invoice::STATUS_PARTIAL])

View File

@ -13,6 +13,7 @@ namespace App\Jobs\Cron;
use App\Models\Project; use App\Models\Project;
use App\Libraries\MultiDB; use App\Libraries\MultiDB;
use Illuminate\Support\Facades\Auth;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
class UpdateCalculatedFields class UpdateCalculatedFields
@ -37,6 +38,8 @@ class UpdateCalculatedFields
{ {
nlog("Updating calculated fields"); nlog("Updating calculated fields");
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
Project::with('tasks')->where('updated_at', '>', now()->subHours(2)) Project::with('tasks')->where('updated_at', '>', now()->subHours(2))

View File

@ -11,13 +11,14 @@
namespace App\Jobs\Ninja; namespace App\Jobs\Ninja;
use App\Libraries\MultiDB;
use App\Models\Scheduler; use App\Models\Scheduler;
use App\Libraries\MultiDB;
use Illuminate\Bus\Queueable; use Illuminate\Bus\Queueable;
use Illuminate\Support\Facades\Auth;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
//@rebuild it //@rebuild it
class TaskScheduler implements ShouldQueue class TaskScheduler implements ShouldQueue
@ -42,6 +43,8 @@ class TaskScheduler implements ShouldQueue
*/ */
public function handle() public function handle()
{ {
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
Scheduler::with('company') Scheduler::with('company')
->where('is_paused', false) ->where('is_paused', false)

View File

@ -19,6 +19,7 @@ use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels; use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Auth;
class CleanStaleInvoiceOrder implements ShouldQueue class CleanStaleInvoiceOrder implements ShouldQueue
{ {
@ -39,6 +40,8 @@ class CleanStaleInvoiceOrder implements ShouldQueue
{ {
nlog("Cleaning Stale Invoices:"); nlog("Cleaning Stale Invoices:");
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
Invoice::query() Invoice::query()
->withTrashed() ->withTrashed()

View File

@ -11,23 +11,22 @@
namespace App\Jobs\Util; namespace App\Jobs\Util;
use App\Utils\Ninja;
use App\Models\Invoice;
use App\Libraries\MultiDB;
use Illuminate\Bus\Queueable;
use Illuminate\Support\Carbon;
use App\DataMapper\InvoiceItem; use App\DataMapper\InvoiceItem;
use App\Factory\InvoiceFactory; use App\Factory\InvoiceFactory;
use App\Jobs\Entity\EmailEntity; use App\Jobs\Entity\EmailEntity;
use App\Jobs\Ninja\TransactionLog;
use App\Libraries\MultiDB;
use App\Models\Invoice;
use App\Models\TransactionEvent;
use App\Utils\Ninja;
use App\Utils\Traits\MakesDates; use App\Utils\Traits\MakesDates;
use Illuminate\Support\Facades\App;
use App\Utils\Traits\MakesReminders; use App\Utils\Traits\MakesReminders;
use Illuminate\Bus\Queueable; use Illuminate\Support\Facades\Auth;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue; use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Carbon;
use Illuminate\Support\Facades\App;
class ReminderJob implements ShouldQueue class ReminderJob implements ShouldQueue
{ {
@ -53,6 +52,8 @@ class ReminderJob implements ShouldQueue
{ {
set_time_limit(0); set_time_limit(0);
Auth::logout();
if (! config('ninja.db.multi_db_enabled')) { if (! config('ninja.db.multi_db_enabled')) {
nlog("Sending invoice reminders on ".now()->format('Y-m-d h:i:s')); nlog("Sending invoice reminders on ".now()->format('Y-m-d h:i:s'));