maintenance: use random minute in cron 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 cron integration. The cron schedule specification starts with a minute indicator, which was previously inserted as the "0" string but now takes the given minute as an integer parameter. 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
9b433990573f02d2078d5a2ee4c227cedd6254bd
1 file changed
+5
-4
builtin/gc.c
+5
-4
@@ -2174,6 +2174,7 @@ static int crontab_update_schedule(int run_maintenance, int fd)
2174
FILE *cron_list, *cron_in;
2175
struct strbuf line = STRBUF_INIT;
2176
struct tempfile *tmpedit = NULL;
2177
+ int minute = get_random_minute();
2178
2179
get_schedule_cmd(&cmd, NULL);
2180
strvec_split(&crontab_list.args, cmd);
@@ -2228,11 +2229,11 @@ static int crontab_update_schedule(int run_maintenance, int fd)
2229
"# replaced in the future by a Git command.\n\n");
2230
2231
strbuf_addf(&line_format,
2231
- "%%s %%s * * %%s \"%s/git\" --exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%%s\n",
2232
+ "%%d %%s * * %%s \"%s/git\" --exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%%s\n",
2233
exec_path, exec_path);
2233
- fprintf(cron_in, line_format.buf, "0", "1-23", "*", "hourly");
2234
- fprintf(cron_in, line_format.buf, "0", "0", "1-6", "daily");
2235
- fprintf(cron_in, line_format.buf, "0", "0", "0", "weekly");
2234
+ fprintf(cron_in, line_format.buf, minute, "1-23", "*", "hourly");
2235
+ fprintf(cron_in, line_format.buf, minute, "0", "1-6", "daily");
2236
+ fprintf(cron_in, line_format.buf, minute, "0", "0", "weekly");
2237
strbuf_release(&line_format);
2238
2239
fprintf(cron_in, "\n%s\n", END_LINE);