diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 6a0213265250..68d37db4b768 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -40,6 +40,10 @@ class Kernel extends ConsoleKernel //$schedule->job(new RecurringInvoicesCron)->hourly(); $schedule->job(new VersionCheck)->daily(); + + /* Build queue snapshots */ + $schedule->command('horizon:snapshot')->everyFiveMinutes(); + } /** diff --git a/app/Http/Controllers/LicenseController.php b/app/Http/Controllers/LicenseController.php index 0e2f516f68d6..70fd5f34d294 100644 --- a/app/Http/Controllers/LicenseController.php +++ b/app/Http/Controllers/LicenseController.php @@ -83,8 +83,8 @@ class LicenseController extends BaseController { /* Catch claim license requests */ - if (config('ninja.environment') == 'selfhost' && $request->has('license_key')) { - $license_key = $request->input('license_key'); + if (config('ninja.environment') == 'selfhost' && request()->has('license_key')) { + $license_key = request()->input('license_key'); $product_id = 3; $url = config('ninja.license_url') . "/claim_license?license_key={$license_key}&product_id={$product_id}&get_date=true"; @@ -134,7 +134,7 @@ class LicenseController extends BaseController } $error = [ - 'message' => trans('texts.invalid_white_label_license'), + 'message' => "Invalid license, or invalid environment ".config('ninja.environment')s, 'errors' => [] ]; diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 2abf72188f92..84ebe146b952 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -646,15 +646,19 @@ class UserController extends BaseController */ public function detach(DetachCompanyUserRequest $request, User $user) { + $company_user = CompanyUser::whereUserId($user->id) ->whereCompanyId(auth()->user()->companyId())->first(); $token = $company_user->token->where('company_id', $company_user->company_id)->where('user_id', $company_user->user_id)->first(); - $token->delete(); + if($token) + $token->delete(); - $company_user->delete(); + if($company_user) + $company_user->delete(); return response()->json(['message' => 'User detached from company'], 200); + } } diff --git a/app/Providers/HorizonServiceProvider.php b/app/Providers/HorizonServiceProvider.php new file mode 100644 index 000000000000..08881175e5ce --- /dev/null +++ b/app/Providers/HorizonServiceProvider.php @@ -0,0 +1,42 @@ +email, [ + // + ]); + }); + } +} diff --git a/composer.json b/composer.json index cd79d9b7cfda..15aa1ec6ac8d 100644 --- a/composer.json +++ b/composer.json @@ -26,11 +26,13 @@ "dacastro4/laravel-gmail": "^3.2", "davejamesmiller/laravel-breadcrumbs": "5.x", "fideloper/proxy": "^4.0", + "fzaninotto/faker": "^1.4", "google/apiclient": "^2.0", "hashids/hashids": "^3.0", "intervention/image": "^2.4", "laracasts/presenter": "^0.2.1", "laravel/framework": "^6", + "laravel/horizon": "3.7.2", "laravel/slack-notification-channel": "^2.0", "laravel/socialite": "^4.0", "laravel/tinker": "^1.0", @@ -46,8 +48,7 @@ "staudenmeir/eloquent-has-many-deep": "^1.11", "stripe/stripe-php": "^7.0", "superbalist/laravel-google-cloud-storage": "^2.2", - "webpatser/laravel-countries": "dev-master#75992ad", - "fzaninotto/faker": "^1.4" + "webpatser/laravel-countries": "dev-master#75992ad" }, "require-dev": { "laravelcollective/html": "^6", @@ -109,4 +110,4 @@ }, "minimum-stability": "dev", "prefer-stable": true -} \ No newline at end of file +} diff --git a/config/app.php b/config/app.php index 4f6e07a20427..c7ea0bfd335a 100644 --- a/config/app.php +++ b/config/app.php @@ -176,6 +176,7 @@ return [ App\Providers\AuthServiceProvider::class, // App\Providers\BroadcastServiceProvider::class, App\Providers\EventServiceProvider::class, + App\Providers\HorizonServiceProvider::class, App\Providers\RouteServiceProvider::class, App\Providers\ComposerServiceProvider::class, Codedge\Updater\UpdaterServiceProvider::class, diff --git a/config/horizon.php b/config/horizon.php new file mode 100644 index 000000000000..90db39ba96f9 --- /dev/null +++ b/config/horizon.php @@ -0,0 +1,164 @@ + null, + + /* + |-------------------------------------------------------------------------- + | Horizon Path + |-------------------------------------------------------------------------- + | + | This is the URI path where Horizon will be accessible from. Feel free + | to change this path to anything you like. Note that the URI will not + | affect the paths of its internal API that aren't exposed to users. + | + */ + + 'path' => 'horizon', + + /* + |-------------------------------------------------------------------------- + | Horizon Redis Connection + |-------------------------------------------------------------------------- + | + | This is the name of the Redis connection where Horizon will store the + | meta information required for it to function. It includes the list + | of supervisors, failed jobs, job metrics, and other information. + | + */ + + 'use' => 'default', + + /* + |-------------------------------------------------------------------------- + | Horizon Redis Prefix + |-------------------------------------------------------------------------- + | + | This prefix will be used when storing all Horizon data in Redis. You + | may modify the prefix when you are running multiple installations + | of Horizon on the same server so that they don't have problems. + | + */ + + 'prefix' => env('HORIZON_PREFIX', 'horizon:'), + + /* + |-------------------------------------------------------------------------- + | Horizon Route Middleware + |-------------------------------------------------------------------------- + | + | These middleware will get attached onto each Horizon route, giving you + | the chance to add your own middleware to this list or change any of + | the existing middleware. Or, you can simply stick with this list. + | + */ + + 'middleware' => ['web'], + + /* + |-------------------------------------------------------------------------- + | Queue Wait Time Thresholds + |-------------------------------------------------------------------------- + | + | This option allows you to configure when the LongWaitDetected event + | will be fired. Every connection / queue combination may have its + | own, unique threshold (in seconds) before this event is fired. + | + */ + + 'waits' => [ + 'redis:default' => 60, + ], + + /* + |-------------------------------------------------------------------------- + | Job Trimming Times + |-------------------------------------------------------------------------- + | + | Here you can configure for how long (in minutes) you desire Horizon to + | persist the recent and failed jobs. Typically, recent jobs are kept + | for one hour while all failed jobs are stored for an entire week. + | + */ + + 'trim' => [ + 'recent' => 60, + 'completed' => 60, + 'recent_failed' => 10080, + 'failed' => 10080, + 'monitored' => 10080, + ], + + /* + |-------------------------------------------------------------------------- + | Fast Termination + |-------------------------------------------------------------------------- + | + | When this option is enabled, Horizon's "terminate" command will not + | wait on all of the workers to terminate unless the --wait option + | is provided. Fast termination can shorten deployment delay by + | allowing a new instance of Horizon to start while the last + | instance will continue to terminate each of its workers. + | + */ + + 'fast_termination' => false, + + /* + |-------------------------------------------------------------------------- + | Memory Limit (MB) + |-------------------------------------------------------------------------- + | + | This value describes the maximum amount of memory the Horizon worker + | may consume before it is terminated and restarted. You should set + | this value according to the resources available to your server. + | + */ + + 'memory_limit' => 256, + + /* + |-------------------------------------------------------------------------- + | Queue Worker Configuration + |-------------------------------------------------------------------------- + | + | Here you may define the queue worker settings used by your application + | in all environments. These supervisors and settings handle all your + | queued jobs and will be provisioned by Horizon during deployment. + | + */ + + 'environments' => [ + 'production' => [ + 'supervisor-1' => [ + 'connection' => 'redis', + 'queue' => ['default'], + 'balance' => 'simple', + 'processes' => 10, + 'tries' => 1, + ], + ], + + 'local' => [ + 'supervisor-1' => [ + 'connection' => 'redis', + 'queue' => ['default'], + 'balance' => 'simple', + 'processes' => 3, + 'tries' => 1, + ], + ], + ], +]; diff --git a/routes/api.php b/routes/api.php index d48e37b1ad15..2a0eb6199ae7 100644 --- a/routes/api.php +++ b/routes/api.php @@ -118,6 +118,8 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::post('self-update/check_version', 'SelfUpdateController@checkVersion'); + Route::post('claim_license', 'LicenseController@index')->name('license.index'); + /* Route::resource('tasks', 'TaskController'); // name = (tasks. index / create / show / update / destroy / edit @@ -136,9 +138,5 @@ Route::group(['middleware' => ['api_db', 'token_auth', 'locale'], 'prefix' => 'a Route::post('support/messages/send', 'Support\Messages\SendingController'); }); -Route::group(['middleware' => ['api_db', 'locale'], 'prefix' => 'api/v1', 'as' => 'api.'], function () { - Route::post('claim_license', 'LicenseController@index')->name('license.index'); - //Route::post('register_user', 'LicenseController@registerNinjaUser')->name('license.register_ninja_user'); -}); Route::fallback('BaseController@notFound');