diff --git a/app/Jobs/ImportData.php b/app/Jobs/ImportData.php index 31271c49e075..b1427775f7ed 100644 --- a/app/Jobs/ImportData.php +++ b/app/Jobs/ImportData.php @@ -34,6 +34,11 @@ class ImportData extends Job implements ShouldQueue */ protected $settings; + /** + * @var string + */ + protected $server; + /** * Create a new job instance. * @@ -45,6 +50,7 @@ class ImportData extends Job implements ShouldQueue $this->user = $user; $this->type = $type; $this->settings = $settings; + $this->server = config('database.default'); } /** diff --git a/app/Jobs/SendInvoiceEmail.php b/app/Jobs/SendInvoiceEmail.php index 04168b609f8e..1046372686ca 100644 --- a/app/Jobs/SendInvoiceEmail.php +++ b/app/Jobs/SendInvoiceEmail.php @@ -38,6 +38,11 @@ class SendInvoiceEmail extends Job implements ShouldQueue */ protected $userId; + /** + * @var string + */ + protected $server; + /** * Create a new job instance. * @@ -52,6 +57,7 @@ class SendInvoiceEmail extends Job implements ShouldQueue $this->userId = $userId; $this->reminder = $reminder; $this->template = $template; + $this->server = config('database.default'); } /** diff --git a/app/Jobs/SendNotificationEmail.php b/app/Jobs/SendNotificationEmail.php index 04fd4fd77c96..e74ace04d10a 100644 --- a/app/Jobs/SendNotificationEmail.php +++ b/app/Jobs/SendNotificationEmail.php @@ -40,6 +40,11 @@ class SendNotificationEmail extends Job implements ShouldQueue */ protected $notes; + /** + * @var string + */ + protected $server; + /** * Create a new job instance. @@ -58,6 +63,7 @@ class SendNotificationEmail extends Job implements ShouldQueue $this->type = $type; $this->payment = $payment; $this->notes = $notes; + $this->server = config('database.default'); } /** diff --git a/app/Jobs/SendPaymentEmail.php b/app/Jobs/SendPaymentEmail.php index e23d291efcec..8e990c00de93 100644 --- a/app/Jobs/SendPaymentEmail.php +++ b/app/Jobs/SendPaymentEmail.php @@ -20,6 +20,11 @@ class SendPaymentEmail extends Job implements ShouldQueue */ protected $payment; + /** + * @var string + */ + protected $server; + /** * Create a new job instance. @@ -28,6 +33,7 @@ class SendPaymentEmail extends Job implements ShouldQueue public function __construct($payment) { $this->payment = $payment; + $this->server = config('database.default'); } /** diff --git a/app/Jobs/SendPushNotification.php b/app/Jobs/SendPushNotification.php index 88a1e59e1789..73acd9299142 100644 --- a/app/Jobs/SendPushNotification.php +++ b/app/Jobs/SendPushNotification.php @@ -25,6 +25,11 @@ class SendPushNotification extends Job implements ShouldQueue */ protected $type; + /** + * @var string + */ + protected $server; + /** * Create a new job instance. @@ -35,6 +40,7 @@ class SendPushNotification extends Job implements ShouldQueue { $this->invoice = $invoice; $this->type = $type; + $this->server = config('database.default'); } /** diff --git a/app/Libraries/Utils.php b/app/Libraries/Utils.php index 695d1661cb39..ff935a32b906 100644 --- a/app/Libraries/Utils.php +++ b/app/Libraries/Utils.php @@ -393,6 +393,7 @@ class Utils 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', 'ip' => Request::getClientIp(), 'count' => Session::get('error_count', 0), + 'is_console' => App::runningInConsole() ? 'yes' : 'no', ]; if ($info) { diff --git a/app/Listeners/InvoiceListener.php b/app/Listeners/InvoiceListener.php index 3888ccbda063..4883667cd89d 100644 --- a/app/Listeners/InvoiceListener.php +++ b/app/Listeners/InvoiceListener.php @@ -153,6 +153,7 @@ class InvoiceListener public function jobFailed(JobExceptionOccurred $exception) { + /* if ($errorEmail = env('ERROR_EMAIL')) { \Mail::raw(print_r($exception->data, true), function ($message) use ($errorEmail) { $message->to($errorEmail) @@ -160,6 +161,7 @@ class InvoiceListener ->subject('Job failed'); }); } + */ Utils::logError($exception->exception); } diff --git a/app/Providers/AppServiceProvider.php b/app/Providers/AppServiceProvider.php index 518076901af9..d9e0bb4635f8 100644 --- a/app/Providers/AppServiceProvider.php +++ b/app/Providers/AppServiceProvider.php @@ -8,6 +8,8 @@ use Request; use URL; use Utils; use Validator; +use Queue; +use Illuminate\Queue\Events\JobProcessing; /** * Class AppServiceProvider. @@ -21,6 +23,14 @@ class AppServiceProvider extends ServiceProvider */ public function boot() { + Queue::before(function (JobProcessing $event) { + $body = $event->job->getRawBody(); + preg_match('/db-ninja-[\d+]/', $body, $matches); + if (count($matches)) { + config(['database.default' => $matches[0]]); + } + }); + Form::macro('image_data', function ($image, $contents = false) { if (! $contents) { $contents = file_get_contents($image); diff --git a/config/queue.php b/config/queue.php index 30e8e8b9d10b..6ee3a7d7f16c 100644 --- a/config/queue.php +++ b/config/queue.php @@ -36,6 +36,7 @@ return [ ], 'database' => [ + 'connection' => env('QUEUE_DATABASE', 'mysql'), 'driver' => 'database', 'table' => 'jobs', 'queue' => 'default', @@ -86,7 +87,8 @@ return [ */ 'failed' => [ - 'database' => 'mysql', 'table' => 'failed_jobs', + 'database' => env('QUEUE_DATABASE', 'mysql'), + 'table' => 'failed_jobs', ], ];