From 5531e405bf8ded9c312a3bb60075be7b07194ad0 Mon Sep 17 00:00:00 2001 From: link2arslan Date: Wed, 26 Oct 2022 16:51:12 +0500 Subject: [PATCH 1/3] adding timezonr functionality for each schedule job --- resources/lang/en/schedule.php | 2 ++ resources/lang/pt_BR/schedule.php | 2 ++ resources/views/form.blade.php | 21 +++++++++++++++++++++ resources/views/index.blade.php | 2 +- src/Console/Scheduling/Schedule.php | 5 ++++- src/Models/Schedule.php | 1 + 6 files changed, 31 insertions(+), 2 deletions(-) diff --git a/resources/lang/en/schedule.php b/resources/lang/en/schedule.php index 6b04f2b..b0fb30d 100644 --- a/resources/lang/en/schedule.php +++ b/resources/lang/en/schedule.php @@ -13,6 +13,7 @@ 'options' => 'Options', 'options_with_value' => 'Options with Value', 'expression' => 'Cron Expression', + 'timezone' => 'Cron timezone', 'log_filename' => 'Log filename', 'output' => 'Output', 'even_in_maintenance_mode' => 'Even in maintenance mode', @@ -39,6 +40,7 @@ 'no-records-found' => 'No records found.', 'save-success' => 'Data saved successfully.', 'save-error' => 'Error saving data.', + 'select-timezone' => 'Select a timezone', 'timezone' => 'All schedules will be executed in the timezone: ', 'select' => 'Select a command', 'custom' => 'Custom Command', diff --git a/resources/lang/pt_BR/schedule.php b/resources/lang/pt_BR/schedule.php index cb95362..9b75448 100644 --- a/resources/lang/pt_BR/schedule.php +++ b/resources/lang/pt_BR/schedule.php @@ -12,6 +12,8 @@ 'options' => 'Opções', 'options_with_value' => 'opções com valor', 'expression' => 'Experessão Cron', + 'select-timezone' => 'Selecione um fuso horário', + 'timezone' => 'Cron fuso horário', 'output' => 'Saída', 'even_in_maintenance_mode' => 'Também em modo de manutenção', 'without_overlapping' => 'Sem sobreposição', diff --git a/resources/views/form.blade.php b/resources/views/form.blade.php index be8e407..f845235 100644 --- a/resources/views/form.blade.php +++ b/resources/views/form.blade.php @@ -2,6 +2,7 @@
command : ''))}}", commands: @json($commandService->get()), + timezones: @json(DateTimeZone::listIdentifiers(DateTimeZone::ALL)), arguments: @json(old('params', (isset($schedule) ? $schedule->params : []))), options: @json(old('options', (isset($schedule) ? $schedule->options : []))), get commandObject() { @@ -153,6 +154,26 @@ class="form-control @error('command_custom') is-invalid @enderror"/> @endif
+ +
+ + + @error('timezone') +
{{ $message }}
+ @enderror +
+ @if(config('database-schedule.enable_groups', false))
diff --git a/resources/views/index.blade.php b/resources/views/index.blade.php index e6618e0..87fb518 100644 --- a/resources/views/index.blade.php +++ b/resources/views/index.blade.php @@ -6,7 +6,7 @@
{{ trans('schedule::schedule.titles.list') }} - {{ trans('schedule::schedule.messages.timezone') }}{{ config('database-schedule.timezone') }} + {{-- {{ trans('schedule::schedule.messages.timezone') }}{{ config('database-schedule.timezone') }} --}} {{ trans('schedule::schedule.titles.back_to_application') }} diff --git a/src/Console/Scheduling/Schedule.php b/src/Console/Scheduling/Schedule.php index d81d9bf..3386be0 100644 --- a/src/Console/Scheduling/Schedule.php +++ b/src/Console/Scheduling/Schedule.php @@ -5,6 +5,7 @@ use RobersonFaria\DatabaseSchedule\Http\Services\ScheduleService; use \Illuminate\Console\Scheduling\Schedule as BaseSchedule; use Illuminate\Support\Facades\Log; +use Config; class Schedule { @@ -46,7 +47,9 @@ private function dispatch($task) array_values($task->getArguments()) + $task->getOptions() ); } - $event->cron($task->expression); + //Setting user timezone + $timezone = ($task->timezone != null)?$task->timezone : Config::get('database-schedule.timezone'); + $event->cron($task->expression)->timezone($timezone); //ensure output is being captured to write history $event->storeOutput(); diff --git a/src/Models/Schedule.php b/src/Models/Schedule.php index 21c2371..1072670 100644 --- a/src/Models/Schedule.php +++ b/src/Models/Schedule.php @@ -48,6 +48,7 @@ class Schedule extends Model 'log_filename', 'groups', 'environments', + 'timezone', ]; protected $attributes = [ From 7a51a68795d93a99d33e71160ad86ceb4e9f560c Mon Sep 17 00:00:00 2001 From: link2arslan Date: Fri, 28 Oct 2022 17:12:44 +0500 Subject: [PATCH 2/3] test issue resolved for timezone --- src/Console/Scheduling/Schedule.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/Console/Scheduling/Schedule.php b/src/Console/Scheduling/Schedule.php index 3386be0..50b5569 100644 --- a/src/Console/Scheduling/Schedule.php +++ b/src/Console/Scheduling/Schedule.php @@ -48,8 +48,16 @@ private function dispatch($task) ); } //Setting user timezone - $timezone = ($task->timezone != null)?$task->timezone : Config::get('database-schedule.timezone'); - $event->cron($task->expression)->timezone($timezone); + if($task->timezone != null){ + $timezone = $task->timezone; + }else{ + $timezone = config('database-schedule.timezone'); + } + if($timezone == null){ + $event->cron($task->expression); + }else{ + $event->cron($task->expression)->timezone($timezone); + } //ensure output is being captured to write history $event->storeOutput(); From 66718ab25c5be0d1e4ce88133602e8f98af1c3ad Mon Sep 17 00:00:00 2001 From: link2arslan Date: Fri, 28 Oct 2022 18:19:47 +0500 Subject: [PATCH 3/3] issue resolved for unit test --- src/Console/Scheduling/Schedule.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Console/Scheduling/Schedule.php b/src/Console/Scheduling/Schedule.php index 50b5569..310390c 100644 --- a/src/Console/Scheduling/Schedule.php +++ b/src/Console/Scheduling/Schedule.php @@ -50,12 +50,12 @@ private function dispatch($task) //Setting user timezone if($task->timezone != null){ $timezone = $task->timezone; - }else{ + } else { $timezone = config('database-schedule.timezone'); } if($timezone == null){ $event->cron($task->expression); - }else{ + } else { $event->cron($task->expression)->timezone($timezone); }