Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding timezonr functionality for each schedule job #56

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions resources/lang/en/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions resources/lang/pt_BR/schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
21 changes: 21 additions & 0 deletions resources/views/form.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<div x-data='{
selectedCommand: "{{old('command', (isset($schedule) ? $schedule->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() {
Expand Down Expand Up @@ -153,6 +154,26 @@ class="form-control @error('command_custom') is-invalid @enderror"/>
@endif
</div>


<div class="form-group">
<label>{{ trans('schedule::schedule.fields.timezone') }}</label>
<select x-model=""
name="timezone"
class="form-control @error('timezone') is-invalid @enderror">
<option value="">{{ trans('schedule::schedule.messages.select-timezone') }}</option>
<template x-for="timezones in timezones">
<option :key="timezones"
:value="timezones"
x-text="timezones"
:selected="timezones == selectedCommand">
</option>
</template>
</select>
@error('timezone')
<div class="invalid-feedback">{{ $message }}</div>
@enderror
</div>

@if(config('database-schedule.enable_groups', false))
<div class="form-group">
<label>{{ trans('schedule::schedule.fields.groups') }}</label>
Expand Down
2 changes: 1 addition & 1 deletion resources/views/index.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<div class="card">
<div class="card-header">{{ trans('schedule::schedule.titles.list') }}
<small><code>
{{ trans('schedule::schedule.messages.timezone') }}{{ config('database-schedule.timezone') }}
{{-- {{ trans('schedule::schedule.messages.timezone') }}{{ config('database-schedule.timezone') }} --}}
</code></small>
<span style="float: right;">
<a href="{{ config('app.url', '/') }}"><i class="bi bi-house-fill"></i> {{ trans('schedule::schedule.titles.back_to_application') }}</a>
Expand Down
13 changes: 12 additions & 1 deletion src/Console/Scheduling/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -46,7 +47,17 @@ private function dispatch($task)
array_values($task->getArguments()) + $task->getOptions()
);
}
$event->cron($task->expression);
//Setting user 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();
Expand Down
1 change: 1 addition & 0 deletions src/Models/Schedule.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ class Schedule extends Model
'log_filename',
'groups',
'environments',
'timezone',
];

protected $attributes = [
Expand Down