mirror of
https://github.com/git/git.git
synced 2026-04-08 07:50:09 +02:00
maintenance: add --schedule option and config
Maintenance currently triggers when certain data-size thresholds are met, such as number of pack-files or loose objects. Users may want to run certain maintenance tasks based on frequency instead. For example, a user may want to perform a 'prefetch' task every hour, or 'gc' task every day. To help these users, update the 'git maintenance run' command to include a '--schedule=<frequency>' option. The allowed frequencies are 'hourly', 'daily', and 'weekly'. These values are also allowed in a new config value 'maintenance.<task>.schedule'. The 'git maintenance run --schedule=<frequency>' checks the '*.schedule' config value for each enabled task to see if the configured frequency is at least as frequent as the frequency from the '--schedule' argument. We use the following order, for full clarity: 'hourly' > 'daily' > 'weekly' Use new 'enum schedule_priority' to track these values numerically. The following cron table would run the scheduled tasks with the correct frequencies: 0 1-23 * * * git -C <repo> maintenance run --schedule=hourly 0 0 * * 1-6 git -C <repo> maintenance run --schedule=daily 0 0 * * 0 git -C <repo> maintenance run --schedule=weekly This cron schedule will run --schedule=hourly every hour except at midnight. This avoids a concurrent run with the --schedule=daily that runs at midnight every day except the first day of the week. This avoids a concurrent run with the --schedule=weekly that runs at midnight on the first day of the week. Since --schedule=daily also runs the 'hourly' tasks and --schedule=weekly runs the 'hourly' and 'daily' tasks, we will still see all tasks run with the proper frequencies. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
committed by
Junio C Hamano
parent
1942d48380
commit
b08ff1fee0
@@ -260,4 +260,44 @@ test_expect_success 'maintenance.incremental-repack.auto' '
|
||||
test_subcommand git multi-pack-index write --no-progress <trace-B
|
||||
'
|
||||
|
||||
test_expect_success '--auto and --schedule incompatible' '
|
||||
test_must_fail git maintenance run --auto --schedule=daily 2>err &&
|
||||
test_i18ngrep "at most one" err
|
||||
'
|
||||
|
||||
test_expect_success 'invalid --schedule value' '
|
||||
test_must_fail git maintenance run --schedule=annually 2>err &&
|
||||
test_i18ngrep "unrecognized --schedule" err
|
||||
'
|
||||
|
||||
test_expect_success '--schedule inheritance weekly -> daily -> hourly' '
|
||||
git config maintenance.loose-objects.enabled true &&
|
||||
git config maintenance.loose-objects.schedule hourly &&
|
||||
git config maintenance.commit-graph.enabled true &&
|
||||
git config maintenance.commit-graph.schedule daily &&
|
||||
git config maintenance.incremental-repack.enabled true &&
|
||||
git config maintenance.incremental-repack.schedule weekly &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/hourly.txt" \
|
||||
git maintenance run --schedule=hourly 2>/dev/null &&
|
||||
test_subcommand git prune-packed --quiet <hourly.txt &&
|
||||
test_subcommand ! git commit-graph write --split --reachable \
|
||||
--no-progress <hourly.txt &&
|
||||
test_subcommand ! git multi-pack-index write --no-progress <hourly.txt &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/daily.txt" \
|
||||
git maintenance run --schedule=daily 2>/dev/null &&
|
||||
test_subcommand git prune-packed --quiet <daily.txt &&
|
||||
test_subcommand git commit-graph write --split --reachable \
|
||||
--no-progress <daily.txt &&
|
||||
test_subcommand ! git multi-pack-index write --no-progress <daily.txt &&
|
||||
|
||||
GIT_TRACE2_EVENT="$(pwd)/weekly.txt" \
|
||||
git maintenance run --schedule=weekly 2>/dev/null &&
|
||||
test_subcommand git prune-packed --quiet <weekly.txt &&
|
||||
test_subcommand git commit-graph write --split --reachable \
|
||||
--no-progress <weekly.txt &&
|
||||
test_subcommand git multi-pack-index write --no-progress <weekly.txt
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
Reference in New Issue
Block a user