Skip to content

Commit 773e1c3

Browse files
committed
return non-zero exit code when file transfers failed
1 parent ce2e942 commit 773e1c3

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ func main() {
5555
}
5656

5757
//start workers
58-
Run(&SharedState{
58+
exitCode := Run(&SharedState{
5959
Configuration: *config,
6060
Context: context.Background(),
6161
})
6262

6363
Gauge("last_run.duration_seconds", int64(time.Since(startTime).Seconds()), 1.0)
6464
Log(LogInfo, "finished in %s", time.Since(startTime).String())
65+
os.Exit(exitCode)
6566
}

threads.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ type SharedState struct {
4444
}
4545

4646
//Run starts and orchestrates the various worker threads.
47-
func Run(state *SharedState) {
47+
func Run(state *SharedState) (exitCode int) {
4848
//receive SIGINT/SIGTERM signals
4949
sigs := make(chan os.Signal, 1)
5050
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
@@ -75,15 +75,19 @@ func Run(state *SharedState) {
7575
Gauge("last_run.files_failed", int64(state.FilesFailed), 1.0)
7676
if state.FilesFailed > 0 {
7777
Gauge("last_run.success", 0, 1.0)
78+
exitCode = 1
7879
} else {
7980
Gauge("last_run.success", 1, 1.0)
81+
exitCode = 0
8082
}
8183

8284
//report results
8385
Log(LogInfo, "%d dirs scanned, %d files found, %d transferred, %d failed",
8486
state.DirectoriesScanned, state.FilesFound,
8587
state.FilesTransferred, state.FilesFailed,
8688
)
89+
90+
return
8791
}
8892

8993
func makeScraperThread(state *SharedState) <-chan File {

0 commit comments

Comments
 (0)