mirror of
https://github.com/git/git
synced 2024-10-30 14:03:28 +00:00
maintenance: use random minute in launchctl 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. Use get_random_minute() when constructing the schedules for launchctl. The format already includes a 'Minute' key which is modified from 0 to the random minute. Signed-off-by: Derrick Stolee <derrickstolee@github.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
89024a0ab0
commit
ec5d9d684c
1 changed files with 12 additions and 11 deletions
23
builtin/gc.c
23
builtin/gc.c
|
@ -1708,7 +1708,6 @@ static int get_schedule_cmd(const char **cmd, int *is_available)
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
MAYBE_UNUSED
|
|
||||||
static int get_random_minute(void)
|
static int get_random_minute(void)
|
||||||
{
|
{
|
||||||
/* Use a static value when under tests. */
|
/* Use a static value when under tests. */
|
||||||
|
@ -1830,6 +1829,7 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit
|
||||||
struct strbuf plist = STRBUF_INIT, plist2 = STRBUF_INIT;
|
struct strbuf plist = STRBUF_INIT, plist2 = STRBUF_INIT;
|
||||||
struct stat st;
|
struct stat st;
|
||||||
const char *cmd = "launchctl";
|
const char *cmd = "launchctl";
|
||||||
|
int minute = get_random_minute();
|
||||||
|
|
||||||
get_schedule_cmd(&cmd, NULL);
|
get_schedule_cmd(&cmd, NULL);
|
||||||
preamble = "<?xml version=\"1.0\"?>\n"
|
preamble = "<?xml version=\"1.0\"?>\n"
|
||||||
|
@ -1855,29 +1855,30 @@ static int launchctl_schedule_plist(const char *exec_path, enum schedule_priorit
|
||||||
case SCHEDULE_HOURLY:
|
case SCHEDULE_HOURLY:
|
||||||
repeat = "<dict>\n"
|
repeat = "<dict>\n"
|
||||||
"<key>Hour</key><integer>%d</integer>\n"
|
"<key>Hour</key><integer>%d</integer>\n"
|
||||||
"<key>Minute</key><integer>0</integer>\n"
|
"<key>Minute</key><integer>%d</integer>\n"
|
||||||
"</dict>\n";
|
"</dict>\n";
|
||||||
for (i = 1; i <= 23; i++)
|
for (i = 1; i <= 23; i++)
|
||||||
strbuf_addf(&plist, repeat, i);
|
strbuf_addf(&plist, repeat, i, minute);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCHEDULE_DAILY:
|
case SCHEDULE_DAILY:
|
||||||
repeat = "<dict>\n"
|
repeat = "<dict>\n"
|
||||||
"<key>Day</key><integer>%d</integer>\n"
|
"<key>Day</key><integer>%d</integer>\n"
|
||||||
"<key>Hour</key><integer>0</integer>\n"
|
"<key>Hour</key><integer>0</integer>\n"
|
||||||
"<key>Minute</key><integer>0</integer>\n"
|
"<key>Minute</key><integer>%d</integer>\n"
|
||||||
"</dict>\n";
|
"</dict>\n";
|
||||||
for (i = 1; i <= 6; i++)
|
for (i = 1; i <= 6; i++)
|
||||||
strbuf_addf(&plist, repeat, i);
|
strbuf_addf(&plist, repeat, i, minute);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SCHEDULE_WEEKLY:
|
case SCHEDULE_WEEKLY:
|
||||||
strbuf_addstr(&plist,
|
strbuf_addf(&plist,
|
||||||
"<dict>\n"
|
"<dict>\n"
|
||||||
"<key>Day</key><integer>0</integer>\n"
|
"<key>Day</key><integer>0</integer>\n"
|
||||||
"<key>Hour</key><integer>0</integer>\n"
|
"<key>Hour</key><integer>0</integer>\n"
|
||||||
"<key>Minute</key><integer>0</integer>\n"
|
"<key>Minute</key><integer>%d</integer>\n"
|
||||||
"</dict>\n");
|
"</dict>\n",
|
||||||
|
minute);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in a new issue