Add setting to enable/disable schedule

This commit is contained in:
Henry Whitaker
2020-12-19 21:47:27 +00:00
parent 1637e66bef
commit 46d13fd08a
2 changed files with 42 additions and 2 deletions

View File

@@ -28,7 +28,9 @@ class Kernel extends ConsoleKernel
*/ */
protected function schedule(Schedule $schedule) protected function schedule(Schedule $schedule)
{ {
if ((bool)SettingsHelper::get('schedule_enabled')->value) {
$schedule->job(new SpeedtestJob(true, config('integrations')))->cron(SettingsHelper::get('schedule')['value']); $schedule->job(new SpeedtestJob(true, config('integrations')))->cron(SettingsHelper::get('schedule')['value']);
}
$schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *'); $schedule->command('speedtest:overview')->cron('0 ' . SettingsHelper::get('speedtest_overview_time')->value . ' * * *');
$schedule->command('speedtest:clear-sessions')->everyMinute(); $schedule->command('speedtest:clear-sessions')->everyMinute();
} }
@@ -40,7 +42,7 @@ class Kernel extends ConsoleKernel
*/ */
protected function commands() protected function commands()
{ {
$this->load(__DIR__.'/Commands'); $this->load(__DIR__ . '/Commands');
require base_path('routes/console.php'); require base_path('routes/console.php');
} }

View File

@@ -0,0 +1,38 @@
<?php
use App\Helpers\SettingsHelper;
use App\Setting;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AddScheduleEnabledSetting extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
if (!SettingsHelper::get('schedule_enabled')) {
Setting::create([
'name' => 'schedule_enabled',
'value' => true,
'description' => 'Enable/disable the schedule worker'
]);
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Setting::whereIn('name', [
'schedule_enabled',
])->delete();
}
}