Skip to content

Commit 9b43399

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 62a2399 commit 9b43399

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

builtin/gc.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2174,6 +2174,7 @@ static int crontab_update_schedule(int run_maintenance, int fd)
21742174
FILE *cron_list, *cron_in;
21752175
struct strbuf line = STRBUF_INIT;
21762176
struct tempfile *tmpedit = NULL;
2177+
int minute = get_random_minute();
21772178

21782179
get_schedule_cmd(&cmd, NULL);
21792180
strvec_split(&crontab_list.args, cmd);
@@ -2228,11 +2229,11 @@ static int crontab_update_schedule(int run_maintenance, int fd)
22282229
"# replaced in the future by a Git command.\n\n");
22292230

22302231
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",
22322233
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");
22362237
strbuf_release(&line_format);
22372238

22382239
fprintf(cron_in, "\n%s\n", END_LINE);

0 commit comments

Comments
 (0)