Add some constants
This commit is contained in:
16
main.go
16
main.go
@@ -19,6 +19,8 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const fileQueueLen = 100
|
const fileQueueLen = 100
|
||||||
|
const fileProcessingDelay = 500 * time.Millisecond
|
||||||
|
const moveAttempts = 100
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
watchDir := "/home/av/temp/inbox"
|
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 {
|
for {
|
||||||
if moveAttempt > 100 {
|
if attempt >= moveAttempts {
|
||||||
log.Printf("Moving failed after %d attempts, see messages", moveAttempt)
|
log.Printf("Moving failed after %d attempts, see messages", attempt)
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -156,19 +158,19 @@ func processFile(filePath, destDir, counterPath string, counter *int) {
|
|||||||
_, err := os.Stat(destPath)
|
_, err := os.Stat(destPath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
log.Printf("Moving failed, file already exists: %s", destPath)
|
log.Printf("Moving failed, file already exists: %s", destPath)
|
||||||
moveAttempt++
|
attempt++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if !errors.Is(err, fs.ErrNotExist) {
|
if !errors.Is(err, fs.ErrNotExist) {
|
||||||
log.Printf("Moving failed: %v", err)
|
log.Printf("Moving failed: %v", err)
|
||||||
moveAttempt++
|
attempt++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := os.Rename(filePath, destPath); err != nil {
|
if err := os.Rename(filePath, destPath); err != nil {
|
||||||
log.Printf("Moving failed: %v", err)
|
log.Printf("Moving failed: %v", err)
|
||||||
moveAttempt++
|
attempt++
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user