Wait for log file after rotation
This commit is contained in:
@@ -33,7 +33,7 @@ func waitForFile(ctx context.Context, path string) (os.FileInfo, error) {
|
|||||||
select {
|
select {
|
||||||
// Check to see if cancellation has been requested
|
// Check to see if cancellation has been requested
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
return nil, nil
|
return os.Stat(path)
|
||||||
default:
|
default:
|
||||||
fi, err = os.Stat(path)
|
fi, err = os.Stat(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -145,7 +145,8 @@ func mirrorLog(ctx context.Context, wg *sync.WaitGroup, path string, fromStart b
|
|||||||
for {
|
for {
|
||||||
// If there's already data there, mirror it now.
|
// If there's already data there, mirror it now.
|
||||||
mirrorAvailableMessages(f, mf)
|
mirrorAvailableMessages(f, mf)
|
||||||
newFI, err := os.Stat(path)
|
// Wait for the new log file (after rotation)
|
||||||
|
newFI, err := waitForFile(ctx, path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
errorChannel <- err
|
errorChannel <- err
|
||||||
@@ -171,7 +172,6 @@ func mirrorLog(ctx context.Context, wg *sync.WaitGroup, path string, fromStart b
|
|||||||
// Don't seek this time, because we know it's a new file
|
// Don't seek this time, because we know it's a new file
|
||||||
mirrorAvailableMessages(f, mf)
|
mirrorAvailableMessages(f, mf)
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
case <-ctx.Done():
|
||||||
log.Debugf("Context cancelled for mirroring %v", path)
|
log.Debugf("Context cancelled for mirroring %v", path)
|
||||||
@@ -181,9 +181,9 @@ func mirrorLog(ctx context.Context, wg *sync.WaitGroup, path string, fromStart b
|
|||||||
}
|
}
|
||||||
// Set a flag, to allow one more time through the loop
|
// Set a flag, to allow one more time through the loop
|
||||||
closing = true
|
closing = true
|
||||||
|
default:
|
||||||
|
time.Sleep(500 * time.Millisecond)
|
||||||
}
|
}
|
||||||
|
|
||||||
time.Sleep(500 * time.Millisecond)
|
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
return errorChannel, nil
|
return errorChannel, nil
|
||||||
|
|||||||
Reference in New Issue
Block a user