Skip to content

Commit 040f70b

Browse files
derrickstoleedscho
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 <derrickstolee@github.com>
1 parent b731f74 commit 040f70b

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
@@ -2217,6 +2217,7 @@ static int crontab_update_schedule(int run_maintenance, int fd)
22172217
FILE *cron_list, *cron_in;
22182218
struct strbuf line = STRBUF_INIT;
22192219
struct tempfile *tmpedit = NULL;
2220+
int minute = get_random_minute();
22202221

22212222
get_schedule_cmd(&cmd, NULL);
22222223
strvec_split(&crontab_list.args, cmd);
@@ -2271,11 +2272,11 @@ static int crontab_update_schedule(int run_maintenance, int fd)
22712272
"# replaced in the future by a Git command.\n\n");
22722273

22732274
strbuf_addf(&line_format,
2274-
"%%s %%s * * %%s \"%s/git\" --exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%%s\n",
2275+
"%%d %%s * * %%s \"%s/git\" --exec-path=\"%s\" for-each-repo --config=maintenance.repo maintenance run --schedule=%%s\n",
22752276
exec_path, exec_path);
2276-
fprintf(cron_in, line_format.buf, "0", "1-23", "*", "hourly");
2277-
fprintf(cron_in, line_format.buf, "0", "0", "1-6", "daily");
2278-
fprintf(cron_in, line_format.buf, "0", "0", "0", "weekly");
2277+
fprintf(cron_in, line_format.buf, minute, "1-23", "*", "hourly");
2278+
fprintf(cron_in, line_format.buf, minute, "0", "1-6", "daily");
2279+
fprintf(cron_in, line_format.buf, minute, "0", "0", "weekly");
22792280
strbuf_release(&line_format);
22802281

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

0 commit comments

Comments
 (0)