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 <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Aug 10, 2023 at 20:39 UTC 62a239987c11d5fbc276b34cf33b95f68384e494
1 file changed +10 -6
builtin/gc.c
+10 -6
@@ -1995,6 +1995,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
1995 const char *frequency = get_frequency(schedule);
1996 char *name = schtasks_task_name(frequency);
1997 struct strbuf tfilename = STRBUF_INIT;
1998 + int minute = get_random_minute();
1999
2000 get_schedule_cmd(&cmd, NULL);
2001
@@ -2015,7 +2016,7 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
2016 switch (schedule) {
2017 case SCHEDULE_HOURLY:
2018 fprintf(tfile->fp,
2018 - "<StartBoundary>2020-01-01T01:00:00</StartBoundary>\n"
2019 + "<StartBoundary>2020-01-01T01:%02d:00</StartBoundary>\n"
2020 "<Enabled>true</Enabled>\n"
2021 "<ScheduleByDay>\n"
2022 "<DaysInterval>1</DaysInterval>\n"
@@ -2024,12 +2025,13 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
2025 "<Interval>PT1H</Interval>\n"
2026 "<Duration>PT23H</Duration>\n"
2027 "<StopAtDurationEnd>false</StopAtDurationEnd>\n"
2027 - "</Repetition>\n");
2028 + "</Repetition>\n",
2029 + minute);
2030 break;
2031
2032 case SCHEDULE_DAILY:
2033 fprintf(tfile->fp,
2032 - "<StartBoundary>2020-01-01T00:00:00</StartBoundary>\n"
2034 + "<StartBoundary>2020-01-01T00:%02d:00</StartBoundary>\n"
2035 "<Enabled>true</Enabled>\n"
2036 "<ScheduleByWeek>\n"
2037 "<DaysOfWeek>\n"
@@ -2041,19 +2043,21 @@ static int schtasks_schedule_task(const char *exec_path, enum schedule_priority
2043 "<Saturday />\n"
2044 "</DaysOfWeek>\n"
2045 "<WeeksInterval>1</WeeksInterval>\n"
2044 - "</ScheduleByWeek>\n");
2046 + "</ScheduleByWeek>\n",
2047 + minute);
2048 break;
2049
2050 case SCHEDULE_WEEKLY:
2051 fprintf(tfile->fp,
2049 - "<StartBoundary>2020-01-01T00:00:00</StartBoundary>\n"
2052 + "<StartBoundary>2020-01-01T00:%02d:00</StartBoundary>\n"
2053 "<Enabled>true</Enabled>\n"
2054 "<ScheduleByWeek>\n"
2055 "<DaysOfWeek>\n"
2056 "<Sunday />\n"
2057 "</DaysOfWeek>\n"
2058 "<WeeksInterval>1</WeeksInterval>\n"
2056 - "</ScheduleByWeek>\n");
2059 + "</ScheduleByWeek>\n",
2060 + minute);
2061 break;
2062
2063 default: