Multi-db support

This commit is contained in:
Hillel Coren 2017-05-04 20:08:27 +03:00
parent 42aef958fe
commit 03bb75674b
9 changed files with 46 additions and 1 deletions

View File

@ -34,6 +34,11 @@ class ImportData extends Job implements ShouldQueue
*/ */
protected $settings; protected $settings;
/**
* @var string
*/
protected $server;
/** /**
* Create a new job instance. * Create a new job instance.
* *
@ -45,6 +50,7 @@ class ImportData extends Job implements ShouldQueue
$this->user = $user; $this->user = $user;
$this->type = $type; $this->type = $type;
$this->settings = $settings; $this->settings = $settings;
$this->server = config('database.default');
} }
/** /**

View File

@ -38,6 +38,11 @@ class SendInvoiceEmail extends Job implements ShouldQueue
*/ */
protected $userId; protected $userId;
/**
* @var string
*/
protected $server;
/** /**
* Create a new job instance. * Create a new job instance.
* *
@ -52,6 +57,7 @@ class SendInvoiceEmail extends Job implements ShouldQueue
$this->userId = $userId; $this->userId = $userId;
$this->reminder = $reminder; $this->reminder = $reminder;
$this->template = $template; $this->template = $template;
$this->server = config('database.default');
} }
/** /**

View File

@ -40,6 +40,11 @@ class SendNotificationEmail extends Job implements ShouldQueue
*/ */
protected $notes; protected $notes;
/**
* @var string
*/
protected $server;
/** /**
* Create a new job instance. * Create a new job instance.
@ -58,6 +63,7 @@ class SendNotificationEmail extends Job implements ShouldQueue
$this->type = $type; $this->type = $type;
$this->payment = $payment; $this->payment = $payment;
$this->notes = $notes; $this->notes = $notes;
$this->server = config('database.default');
} }
/** /**

View File

@ -20,6 +20,11 @@ class SendPaymentEmail extends Job implements ShouldQueue
*/ */
protected $payment; protected $payment;
/**
* @var string
*/
protected $server;
/** /**
* Create a new job instance. * Create a new job instance.
@ -28,6 +33,7 @@ class SendPaymentEmail extends Job implements ShouldQueue
public function __construct($payment) public function __construct($payment)
{ {
$this->payment = $payment; $this->payment = $payment;
$this->server = config('database.default');
} }
/** /**

View File

@ -25,6 +25,11 @@ class SendPushNotification extends Job implements ShouldQueue
*/ */
protected $type; protected $type;
/**
* @var string
*/
protected $server;
/** /**
* Create a new job instance. * Create a new job instance.
@ -35,6 +40,7 @@ class SendPushNotification extends Job implements ShouldQueue
{ {
$this->invoice = $invoice; $this->invoice = $invoice;
$this->type = $type; $this->type = $type;
$this->server = config('database.default');
} }
/** /**

View File

@ -393,6 +393,7 @@ class Utils
'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '', 'user_agent' => isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : '',
'ip' => Request::getClientIp(), 'ip' => Request::getClientIp(),
'count' => Session::get('error_count', 0), 'count' => Session::get('error_count', 0),
'is_console' => App::runningInConsole() ? 'yes' : 'no',
]; ];
if ($info) { if ($info) {

View File

@ -153,6 +153,7 @@ class InvoiceListener
public function jobFailed(JobExceptionOccurred $exception) public function jobFailed(JobExceptionOccurred $exception)
{ {
/*
if ($errorEmail = env('ERROR_EMAIL')) { if ($errorEmail = env('ERROR_EMAIL')) {
\Mail::raw(print_r($exception->data, true), function ($message) use ($errorEmail) { \Mail::raw(print_r($exception->data, true), function ($message) use ($errorEmail) {
$message->to($errorEmail) $message->to($errorEmail)
@ -160,6 +161,7 @@ class InvoiceListener
->subject('Job failed'); ->subject('Job failed');
}); });
} }
*/
Utils::logError($exception->exception); Utils::logError($exception->exception);
} }

View File

@ -8,6 +8,8 @@ use Request;
use URL; use URL;
use Utils; use Utils;
use Validator; use Validator;
use Queue;
use Illuminate\Queue\Events\JobProcessing;
/** /**
* Class AppServiceProvider. * Class AppServiceProvider.
@ -21,6 +23,14 @@ class AppServiceProvider extends ServiceProvider
*/ */
public function boot() 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) { Form::macro('image_data', function ($image, $contents = false) {
if (! $contents) { if (! $contents) {
$contents = file_get_contents($image); $contents = file_get_contents($image);

View File

@ -36,6 +36,7 @@ return [
], ],
'database' => [ 'database' => [
'connection' => env('QUEUE_DATABASE', 'mysql'),
'driver' => 'database', 'driver' => 'database',
'table' => 'jobs', 'table' => 'jobs',
'queue' => 'default', 'queue' => 'default',
@ -86,7 +87,8 @@ return [
*/ */
'failed' => [ 'failed' => [
'database' => 'mysql', 'table' => 'failed_jobs', 'database' => env('QUEUE_DATABASE', 'mysql'),
'table' => 'failed_jobs',
], ],
]; ];