1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 14:12:44 +01:00

Clean up for scheduler

This commit is contained in:
David Bomba 2023-01-13 20:23:03 +11:00
parent 9e5417ab1c
commit 35fde4a73e
3 changed files with 54 additions and 56 deletions

View File

@ -71,7 +71,7 @@ class Kernel extends ConsoleKernel
$schedule->job(new RecurringInvoicesCron)->hourly()->withoutOverlapping()->name('recurring-invoice-job')->onOneServer();
/* Stale Invoice Cleanup*/
$schedule->job(new CleanStaleInvoiceOrder)->hourly()->withoutOverlapping()->name('stale-invoice-job')->onOneServer();
$schedule->job(new CleanStaleInvoiceOrder)->hourlyAt(30)->withoutOverlapping()->name('stale-invoice-job')->onOneServer();
/* Sends recurring invoices*/
$schedule->job(new RecurringExpensesCron)->dailyAt('00:10')->withoutOverlapping()->name('recurring-expense-job')->onOneServer();
@ -89,7 +89,7 @@ class Kernel extends ConsoleKernel
$schedule->job(new SchedulerCheck)->dailyAt('01:10')->withoutOverlapping();
/* Checks for scheduled tasks */
$schedule->job(new TaskScheduler())->dailyAt('06:50')->withoutOverlapping()->name('task-scheduler-job')->onOneServer();
$schedule->job(new TaskScheduler())->hourlyAt(10)->withoutOverlapping()->name('task-scheduler-job')->onOneServer();
/* Performs system maintenance such as pruning the backup table */
$schedule->job(new SystemMaintenance)->sundays()->at('02:30')->withoutOverlapping()->name('system-maintenance-job')->onOneServer();

View File

@ -28,8 +28,9 @@ class StoreSchedulerRequest extends Request
public function rules()
{
nlog($this->all());
$rules = [
'name' => ['bail', 'required', Rule::unique('schedulers')->where('company_id', auth()->user()->company()->id)],
'is_paused' => 'bail|sometimes|boolean',
'frequency_id' => 'bail|required|integer|digits_between:1,12',
'next_run' => 'bail|required|date:Y-m-d',
@ -37,10 +38,6 @@ nlog($this->all());
'parameters' => 'bail|array',
];
$rules['name'] = ['bail', 'required', Rule::unique('schedulers')->where('company_id', auth()->user()->company()->id)];
nlog($rules);
return $rules;
}

View File

@ -46,9 +46,10 @@ class TaskScheduler implements ShouldQueue
MultiDB::setDB($db);
Scheduler::with('company')
->where('paused', false)
->where('is_paused', false)
->where('is_deleted', false)
->where('scheduled_run', '<', now())
->whereNotNull('next_run')
->where('next_run', '<=', now())
->cursor()
->each(function ($scheduler) {
$this->doJob($scheduler);
@ -62,55 +63,55 @@ class TaskScheduler implements ShouldQueue
$company = $scheduler->company;
$parameters = $scheduler->parameters;
// $parameters = $scheduler->parameters;
switch ($scheduler->action_name) {
case Scheduler::CREATE_CLIENT_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'contacts.csv');
break;
case Scheduler::CREATE_CLIENT_CONTACT_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'clients.csv');
break;
case Scheduler::CREATE_CREDIT_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'credits.csv');
break;
case Scheduler::CREATE_DOCUMENT_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'documents.csv');
break;
case Scheduler::CREATE_EXPENSE_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'expense.csv');
break;
case Scheduler::CREATE_INVOICE_ITEM_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'invoice_items.csv');
break;
case Scheduler::CREATE_INVOICE_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'invoices.csv');
break;
case Scheduler::CREATE_PAYMENT_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'payments.csv');
break;
case Scheduler::CREATE_PRODUCT_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'products.csv');
break;
case Scheduler::CREATE_PROFIT_AND_LOSS_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'profit_and_loss.csv');
break;
case Scheduler::CREATE_QUOTE_ITEM_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'quote_items.csv');
break;
case Scheduler::CREATE_QUOTE_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'quotes.csv');
break;
case Scheduler::CREATE_RECURRING_INVOICE_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'recurring_invoices.csv');
break;
case Scheduler::CREATE_TASK_REPORT:
SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'tasks.csv');
break;
// switch ($scheduler->action_name) {
// case Scheduler::CREATE_CLIENT_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'contacts.csv');
// break;
// case Scheduler::CREATE_CLIENT_CONTACT_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'clients.csv');
// break;
// case Scheduler::CREATE_CREDIT_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'credits.csv');
// break;
// case Scheduler::CREATE_DOCUMENT_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'documents.csv');
// break;
// case Scheduler::CREATE_EXPENSE_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'expense.csv');
// break;
// case Scheduler::CREATE_INVOICE_ITEM_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'invoice_items.csv');
// break;
// case Scheduler::CREATE_INVOICE_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'invoices.csv');
// break;
// case Scheduler::CREATE_PAYMENT_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'payments.csv');
// break;
// case Scheduler::CREATE_PRODUCT_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'products.csv');
// break;
// case Scheduler::CREATE_PROFIT_AND_LOSS_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'profit_and_loss.csv');
// break;
// case Scheduler::CREATE_QUOTE_ITEM_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'quote_items.csv');
// break;
// case Scheduler::CREATE_QUOTE_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'quotes.csv');
// break;
// case Scheduler::CREATE_RECURRING_INVOICE_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'recurring_invoices.csv');
// break;
// case Scheduler::CREATE_TASK_REPORT:
// SendToAdmin::dispatch($company, $parameters, $scheduler->action_class, 'tasks.csv');
// break;
}
// }
$scheduler->scheduled_run = $scheduler->nextScheduledDate();
$scheduler->save();
// $scheduler->scheduled_run = $scheduler->nextScheduledDate();
// $scheduler->save();
}
}