Skip to content

Commit 62a2399

Browse files
derrickstoleegitster
authored andcommitted
maintenance: use random minute in Windows scheduler
The get_random_minute() method was created to allow maintenance schedules to be fixed to a random minute of the hour. This randomness is only intended to spread out the load from a number of clients, but each client should have an hour between each maintenance cycle. Add this random minute to the Windows scheduler integration. We need only to modify the minute value for the 'StartBoundary' tag across the three schedules. Signed-off-by: Derrick Stolee <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent ec5d9d6 commit 62a2399

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

builtin/gc.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1995,6 +1995,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
19951995
const char *frequency = get_frequency(schedule);
19961996
char *name = schtasks_task_name(frequency);
19971997
struct strbuf tfilename = STRBUF_INIT;
1998+
int minute = get_random_minute();
19981999

19992000
get_schedule_cmd(&cmd, NULL);
20002001

@@ -2015,7 +2016,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
20152016
switch (schedule) {
20162017
case SCHEDULE_HOURLY:
20172018
fprintf(tfile->fp,
2018-
"<StartBoundary>2020-01-01T01:00:00</StartBoundary>\n"
2019+
"<StartBoundary>2020-01-01T01:%02d:00</StartBoundary>\n"
20192020
"<Enabled>true</Enabled>\n"
20202021
"<ScheduleByDay>\n"
20212022
"<DaysInterval>1</DaysInterval>\n"
@@ -2024,12 +2025,13 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
20242025
"<Interval>PT1H</Interval>\n"
20252026
"<Duration>PT23H</Duration>\n"
20262027
"<StopAtDurationEnd>false</StopAtDurationEnd>\n"
2027-
"</Repetition>\n");
2028+
"</Repetition>\n",
2029+
minute);
20282030
break;
20292031

20302032
case SCHEDULE_DAILY:
20312033
fprintf(tfile->fp,
2032-
"<StartBoundary>2020-01-01T00:00:00</StartBoundary>\n"
2034+
"<StartBoundary>2020-01-01T00:%02d:00</StartBoundary>\n"
20332035
"<Enabled>true</Enabled>\n"
20342036
"<ScheduleByWeek>\n"
20352037
"<DaysOfWeek>\n"
@@ -2041,19 +2043,21 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
20412043
"<Saturday />\n"
20422044
"</DaysOfWeek>\n"
20432045
"<WeeksInterval>1</WeeksInterval>\n"
2044-
"</ScheduleByWeek>\n");
2046+
"</ScheduleByWeek>\n",
2047+
minute);
20452048
break;
20462049

20472050
case SCHEDULE_WEEKLY:
20482051
fprintf(tfile->fp,
2049-
"<StartBoundary>2020-01-01T00:00:00</StartBoundary>\n"
2052+
"<StartBoundary>2020-01-01T00:%02d:00</StartBoundary>\n"
20502053
"<Enabled>true</Enabled>\n"
20512054
"<ScheduleByWeek>\n"
20522055
"<DaysOfWeek>\n"
20532056
"<Sunday />\n"
20542057
"</DaysOfWeek>\n"
20552058
"<WeeksInterval>1</WeeksInterval>\n"
2056-
"</ScheduleByWeek>\n");
2059+
"</ScheduleByWeek>\n",
2060+
minute);
20572061
break;
20582062

20592063
default:

0 commit comments

Comments
 (0)