1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-08 20:22:42 +01:00

Use queues in send reminders command

This commit is contained in:
Hillel Coren 2018-03-27 15:56:04 +03:00
parent d2e39f9c6c
commit 497154becb

View File

@ -6,9 +6,10 @@ use App\Libraries\CurlUtils;
use Carbon;
use Str;
use Cache;
use Exception;
use App\Jobs\SendInvoiceEmail;
use App\Models\Invoice;
use App\Models\Currency;
use App\Ninja\Mailers\ContactMailer as Mailer;
use App\Ninja\Mailers\UserMailer;
use App\Ninja\Repositories\AccountRepository;
use App\Ninja\Repositories\InvoiceRepository;
@ -33,11 +34,6 @@ class SendReminders extends Command
*/
protected $description = 'Send reminder emails';
/**
* @var Mailer
*/
protected $mailer;
/**
* @var InvoiceRepository
*/
@ -55,11 +51,10 @@ class SendReminders extends Command
* @param InvoiceRepository $invoiceRepo
* @param accountRepository $accountRepo
*/
public function __construct(Mailer $mailer, InvoiceRepository $invoiceRepo, AccountRepository $accountRepo, UserMailer $userMailer)
public function __construct(InvoiceRepository $invoiceRepo, AccountRepository $accountRepo, UserMailer $userMailer)
{
parent::__construct();
$this->mailer = $mailer;
$this->invoiceRepo = $invoiceRepo;
$this->accountRepo = $accountRepo;
$this->userMailer = $userMailer;
@ -136,7 +131,7 @@ class SendReminders extends Command
continue;
}
$this->info('Send email: ' . $invoice->id);
$this->mailer->sendInvoice($invoice, $reminder);
dispatch(new SendInvoiceEmail($invoice, $invoice->user_id, $reminder));
}
}
@ -149,7 +144,7 @@ class SendReminders extends Command
continue;
}
$this->info('Send email: ' . $invoice->id);
$this->mailer->sendInvoice($invoice, 'reminder4');
dispatch(new SendInvoiceEmail($invoice, $invoice->user_id, 'reminder4'));
}
}
}
@ -162,6 +157,8 @@ class SendReminders extends Command
$this->info($scheduledReports->count() . ' scheduled reports');
foreach ($scheduledReports as $scheduledReport) {
$this->info('Processing report: ' . $scheduledReport->id);
$user = $scheduledReport->user;
$account = $scheduledReport->account;
@ -179,7 +176,14 @@ class SendReminders extends Command
$file = dispatch(new ExportReportResults($scheduledReport->user, $config['export_format'], $reportType, $report->exportParams));
if ($file) {
$this->userMailer->sendScheduledReport($scheduledReport, $file);
try {
$this->userMailer->sendScheduledReport($scheduledReport, $file);
$this->info('Sent report');
} catch (Exception $exception) {
$this->info('ERROR: ' . $exception->getMessage());
}
} else {
$this->info('ERROR: Failed to run report');
}
$scheduledReport->updateSendDate();