use repo.MaxTime as rsync --timeout value

This commit is contained in:
Max Erenberg 2024-05-18 21:04:01 -04:00 committed by Mirror
parent 333227414c
commit 8a07f7b58a
3 changed files with 8 additions and 7 deletions

View File

@ -26,7 +26,7 @@ const (
DEAFULT_HOSTNAME = "mirror.csclub.uwaterloo.ca"
DEFAULT_MAX_JOBS = 6
DEFAULT_MAX_TIME = DAILY / 4
DEFAULT_MAX_TIME = 3600
DEFAULT_MAX_RSYNC_IO = 0
DEFAULT_SYNC_TYPE = "csc-sync-standard"
DEFAULT_FREQUENCY_STRING = "bi-hourly"
@ -121,7 +121,7 @@ type Repo struct {
// instead of spawning a process sleep for 50 seconds instead (default: false)
DryRun bool `ini:"dry_run"`
// the maximum time (in seconds) that each child process of this repo
// can for before being killed
// can run for before being killed (passed to rsync as --timeout)
MaxTime int `ini:"max_time"`
// limit the amount of bandwidth a repo can use while syncing
// (set to 0 to disable the limit) (unit is KiB)

View File

@ -77,7 +77,7 @@ func getSyncCommand(repo *config.Repo) (cmds [][]string) {
const (
noOwnerNoGroup = 1 << iota
timeout3600
withTimeout // value is taken from repo.MaxTime
excludeTmp
logFile
quiet
@ -86,7 +86,7 @@ const (
delete
delayUpdatesDeleteAfter
// adds base arguments for setting timeout, a logfile, and including quiet
baseFlags = timeout3600 | logFile | quiet
baseFlags = withTimeout | logFile | quiet
// adds standard arguments timeout, logging, quiet, no owner/group, and excluding .~tmp~/
stdFlags = baseFlags | noOwnerNoGroup | excludeTmp
)
@ -96,8 +96,8 @@ func addConditionalFlags(repo *config.Repo, flags int) []string {
if flags&noOwnerNoGroup != 0 {
args = append(args, "--no-owner", "--no-group")
}
if flags&timeout3600 != 0 {
args = append(args, "--timeout=3600")
if flags&withTimeout != 0 {
args = append(args, fmt.Sprintf("--timeout=%d", repo.MaxTime))
}
if flags&excludeTmp != 0 {
args = append(args, "--exclude", ".~tmp~/")

View File

@ -73,7 +73,8 @@ func spawnProcess(repo *config.Repo, args []string) (ch <-chan *exec.Cmd) {
defer func() {
cmdChan <- cmd
}()
timer := time.NewTimer(time.Duration(repo.MaxTime) * time.Second)
// Add an extra 5 seconds to give rsync a chance to exit on its own (--timeout)
timer := time.NewTimer(time.Duration(repo.MaxTime+5) * time.Second)
defer timer.Stop()
select {
case <-cmdDoneChan: