Skip to content

Commit ffeedf1

Browse files
Adds months for schedules
Adds month variable for schedules
1 parent 9684456 commit ffeedf1

File tree

12 files changed

+65
-11
lines changed

12 files changed

+65
-11
lines changed

app/Helpers/Utilities.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,13 +42,14 @@ public static function randomStringWithSpecialCharacters(int $length = 16): stri
4242
* @param string $minute
4343
* @param string $hour
4444
* @param string $dayOfMonth
45+
* @param string $month
4546
* @param string $dayOfWeek
4647
* @return \Carbon\Carbon
4748
*/
48-
public static function getScheduleNextRunDate(string $minute, string $hour, string $dayOfMonth, string $dayOfWeek)
49+
public static function getScheduleNextRunDate(string $minute, string $hour, string $dayOfMonth, string $month, string $dayOfWeek)
4950
{
5051
return Carbon::instance(CronExpression::factory(
51-
sprintf('%s %s %s * %s', $minute, $hour, $dayOfMonth, $dayOfWeek)
52+
sprintf('%s %s %s %s %s', $minute, $hour, $dayOfMonth, $month, $dayOfWeek)
5253
)->getNextRunDate());
5354
}
5455

app/Http/Controllers/Api/Client/Servers/ScheduleController.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ public function store(StoreScheduleRequest $request, Server $server)
8484
'server_id' => $server->id,
8585
'name' => $request->input('name'),
8686
'cron_day_of_week' => $request->input('day_of_week'),
87+
'cron_month' => $request->input('month'),
8788
'cron_day_of_month' => $request->input('day_of_month'),
8889
'cron_hour' => $request->input('hour'),
8990
'cron_minute' => $request->input('minute'),
@@ -136,6 +137,7 @@ public function update(UpdateScheduleRequest $request, Server $server, Schedule
136137
$data = [
137138
'name' => $request->input('name'),
138139
'cron_day_of_week' => $request->input('day_of_week'),
140+
'cron_month' => $request->input('month'),
139141
'cron_day_of_month' => $request->input('day_of_month'),
140142
'cron_hour' => $request->input('hour'),
141143
'cron_minute' => $request->input('minute'),
@@ -211,6 +213,7 @@ protected function getNextRunAt(Request $request): Carbon
211213
$request->input('minute'),
212214
$request->input('hour'),
213215
$request->input('day_of_month'),
216+
$request->input('month'),
214217
$request->input('day_of_week')
215218
);
216219
} catch (Exception $exception) {

app/Models/Schedule.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* @property int $server_id
1313
* @property string $name
1414
* @property string $cron_day_of_week
15+
* @property string $cron_month
1516
* @property string $cron_day_of_month
1617
* @property string $cron_hour
1718
* @property string $cron_minute
@@ -58,6 +59,7 @@ class Schedule extends Model
5859
'server_id',
5960
'name',
6061
'cron_day_of_week',
62+
'cron_month',
6163
'cron_day_of_month',
6264
'cron_hour',
6365
'cron_minute',
@@ -93,6 +95,7 @@ class Schedule extends Model
9395
protected $attributes = [
9496
'name' => null,
9597
'cron_day_of_week' => '*',
98+
'cron_month' => '*',
9699
'cron_day_of_month' => '*',
97100
'cron_hour' => '*',
98101
'cron_minute' => '*',
@@ -107,6 +110,7 @@ class Schedule extends Model
107110
'server_id' => 'required|exists:servers,id',
108111
'name' => 'required|string|max:191',
109112
'cron_day_of_week' => 'required|string',
113+
'cron_month' => 'required|string',
110114
'cron_day_of_month' => 'required|string',
111115
'cron_hour' => 'required|string',
112116
'cron_minute' => 'required|string',
@@ -123,7 +127,7 @@ class Schedule extends Model
123127
*/
124128
public function getNextRunDate()
125129
{
126-
$formatted = sprintf('%s %s %s * %s', $this->cron_minute, $this->cron_hour, $this->cron_day_of_month, $this->cron_day_of_week);
130+
$formatted = sprintf('%s %s %s %s %s', $this->cron_minute, $this->cron_hour, $this->cron_day_of_month, $this->cron_month, $this->cron_day_of_week);
127131

128132
return CarbonImmutable::createFromTimestamp(
129133
CronExpression::factory($formatted)->getNextRunDate()->getTimestamp()

app/Transformers/Api/Client/ScheduleTransformer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public function transform(Schedule $model)
4040
'cron' => [
4141
'day_of_week' => $model->cron_day_of_week,
4242
'day_of_month' => $model->cron_day_of_month,
43+
'month' => $model->cron_month,
4344
'hour' => $model->cron_hour,
4445
'minute' => $model->cron_minute,
4546
],
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
use Illuminate\Database\Migrations\Migration;
4+
use Illuminate\Database\Schema\Blueprint;
5+
use Illuminate\Support\Facades\Schema;
6+
7+
class AddCronMonth extends Migration
8+
{
9+
/**
10+
* Run the migrations.
11+
*
12+
* @return void
13+
*/
14+
public function up()
15+
{
16+
Schema::table('schedules', function (Blueprint $table) {
17+
$table->string('cron_month')->after('cron_day_of_week');
18+
});
19+
}
20+
21+
/**
22+
* Reverse the migrations.
23+
*
24+
* @return void
25+
*/
26+
public function down()
27+
{
28+
Schema::table('schedules', function (Blueprint $table) {
29+
$table->dropColumn('cron_month');
30+
});
31+
}
32+
}

resources/scripts/api/server/schedules/createOrUpdateSchedule.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export default (uuid: string, schedule: Data): Promise<Schedule> => {
1111
minute: schedule.cron.minute,
1212
hour: schedule.cron.hour,
1313
day_of_month: schedule.cron.dayOfMonth,
14+
month: schedule.cron.month,
1415
day_of_week: schedule.cron.dayOfWeek,
1516
})
1617
.then(({ data }) => resolve(rawDataToServerSchedule(data.attributes)))

resources/scripts/api/server/schedules/getServerSchedules.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ export interface Schedule {
55
name: string;
66
cron: {
77
dayOfWeek: string;
8+
month: string;
89
dayOfMonth: string;
910
hour: string;
1011
minute: string;
@@ -46,6 +47,7 @@ export const rawDataToServerSchedule = (data: any): Schedule => ({
4647
name: data.name,
4748
cron: {
4849
dayOfWeek: data.cron.day_of_week,
50+
month: data.cron.month,
4951
dayOfMonth: data.cron.day_of_month,
5052
hour: data.cron.hour,
5153
minute: data.cron.minute,

resources/scripts/components/server/schedules/EditScheduleModal.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ type Props = {
1919
interface Values {
2020
name: string;
2121
dayOfWeek: string;
22+
month: string;
2223
dayOfMonth: string;
2324
hour: string;
2425
minute: string;
@@ -38,7 +39,7 @@ const EditScheduleModal = ({ schedule, ...props }: Omit<Props, 'onScheduleUpdate
3839
label={'Schedule name'}
3940
description={'A human readable identifer for this schedule.'}
4041
/>
41-
<div css={tw`grid grid-cols-2 sm:grid-cols-4 gap-4 mt-6`}>
42+
<div css={tw`grid grid-cols-2 sm:grid-cols-5 gap-4 mt-6`}>
4243
<div>
4344
<Field name={'minute'} label={'Minute'}/>
4445
</div>
@@ -48,6 +49,9 @@ const EditScheduleModal = ({ schedule, ...props }: Omit<Props, 'onScheduleUpdate
4849
<div>
4950
<Field name={'dayOfMonth'} label={'Day of month'}/>
5051
</div>
52+
<div>
53+
<Field name={'month'} label={'Month'}/>
54+
</div>
5155
<div>
5256
<Field name={'dayOfWeek'} label={'Day of week'}/>
5357
</div>
@@ -94,6 +98,7 @@ export default ({ schedule, visible, ...props }: Props) => {
9498
minute: values.minute,
9599
hour: values.hour,
96100
dayOfWeek: values.dayOfWeek,
101+
month: values.month,
97102
dayOfMonth: values.dayOfMonth,
98103
},
99104
isActive: values.enabled,
@@ -116,10 +121,11 @@ export default ({ schedule, visible, ...props }: Props) => {
116121
onSubmit={submit}
117122
initialValues={{
118123
name: schedule?.name || '',
119-
dayOfWeek: schedule?.cron.dayOfWeek || '*',
120-
dayOfMonth: schedule?.cron.dayOfMonth || '*',
121-
hour: schedule?.cron.hour || '*',
122124
minute: schedule?.cron.minute || '*/5',
125+
hour: schedule?.cron.hour || '*',
126+
dayOfMonth: schedule?.cron.dayOfMonth || '*',
127+
month: schedule?.cron.month || '*',
128+
dayOfWeek: schedule?.cron.dayOfWeek || '*',
123129
enabled: schedule ? schedule.isActive : true,
124130
} as Values}
125131
validationSchema={null}

resources/scripts/components/server/schedules/ScheduleCronRow.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ const ScheduleCronRow = ({ cron, className }: Props) => (
2222
<p css={tw`text-2xs text-neutral-500 uppercase`}>Day (Month)</p>
2323
</div>
2424
<div css={tw`w-1/5 sm:w-auto text-center ml-4`}>
25-
<p css={tw`font-medium`}>*</p>
25+
<p css={tw`font-medium`}>{cron.month}</p>
2626
<p css={tw`text-2xs text-neutral-500 uppercase`}>Month</p>
2727
</div>
2828
<div css={tw`w-1/5 sm:w-auto text-center ml-4`}>

resources/scripts/components/server/schedules/ScheduleEditContainer.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ export default () => {
8888
:
8989
<>
9090
<ScheduleCronRow cron={schedule.cron} css={tw`sm:hidden bg-neutral-700 rounded mb-4 p-3`}/>
91-
<div css={tw`hidden sm:grid grid-cols-5 md:grid-cols-7 gap-4 mb-6`}>
91+
<div css={tw`hidden sm:grid grid-cols-6 md:grid-cols-7 gap-4 mb-6`}>
9292
<CronBox title={'Minute'} value={schedule.cron.minute}/>
9393
<CronBox title={'Hour'} value={schedule.cron.hour}/>
9494
<CronBox title={'Day (Month)'} value={schedule.cron.dayOfMonth}/>
95-
<CronBox title={'Month'} value={'*'}/>
95+
<CronBox title={'Month'} value={schedule.cron.month}/>
9696
<CronBox title={'Day (Week)'} value={schedule.cron.dayOfWeek}/>
9797
</div>
9898
<div css={tw`rounded shadow`}>

0 commit comments

Comments
 (0)