Add some constants
This commit is contained in:
16
main.go
16
main.go
@@ -19,6 +19,8 @@ import (
|
||||
)
|
||||
|
||||
const fileQueueLen = 100
|
||||
const fileProcessingDelay = 500 * time.Millisecond
|
||||
const moveAttempts = 100
|
||||
|
||||
func main() {
|
||||
watchDir := "/home/av/temp/inbox"
|
||||
@@ -137,13 +139,13 @@ func processFile(filePath, destDir, counterPath string, counter *int) {
|
||||
}
|
||||
|
||||
// Ожидание завершения записи
|
||||
time.Sleep(500 * time.Millisecond)
|
||||
time.Sleep(fileProcessingDelay)
|
||||
|
||||
moveAttempt := 0
|
||||
attempt := 0
|
||||
|
||||
for {
|
||||
if moveAttempt > 100 {
|
||||
log.Printf("Moving failed after %d attempts, see messages", moveAttempt)
|
||||
if attempt >= moveAttempts {
|
||||
log.Printf("Moving failed after %d attempts, see messages", attempt)
|
||||
break
|
||||
}
|
||||
|
||||
@@ -156,19 +158,19 @@ func processFile(filePath, destDir, counterPath string, counter *int) {
|
||||
_, err := os.Stat(destPath)
|
||||
if err == nil {
|
||||
log.Printf("Moving failed, file already exists: %s", destPath)
|
||||
moveAttempt++
|
||||
attempt++
|
||||
continue
|
||||
}
|
||||
|
||||
if !errors.Is(err, fs.ErrNotExist) {
|
||||
log.Printf("Moving failed: %v", err)
|
||||
moveAttempt++
|
||||
attempt++
|
||||
continue
|
||||
}
|
||||
|
||||
if err := os.Rename(filePath, destPath); err != nil {
|
||||
log.Printf("Moving failed: %v", err)
|
||||
moveAttempt++
|
||||
attempt++
|
||||
continue
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user