File tree Expand file tree Collapse file tree 2 files changed +11
-8
lines changed
Expand file tree Collapse file tree 2 files changed +11
-8
lines changed Original file line number Diff line number Diff line change 11package internal
22
33import (
4+ "context"
45 "log"
56 "os"
67 "path"
78 "time"
89)
910
10- func StartScheduler (shutdown chan os. Signal ) {
11+ func StartScheduler (ctx context. Context ) {
1112 hourlyChecker := time .NewTicker (1 * time .Hour )
1213 defer hourlyChecker .Stop ()
1314
1415 for {
1516 select {
16- case <- shutdown :
17+ case <- ctx . Done () :
1718 log .Println ("Stopping scheduler" )
1819 return
1920 case <- hourlyChecker .C :
Original file line number Diff line number Diff line change 11package main
22
33import (
4+ "context"
45 "fmt"
56 "log"
67 "os"
78 "os/signal"
89 "syscall"
10+ "time"
911
1012 "github.com/jibon57/secure-file-download-server/internal"
1113 "gopkg.in/yaml.v3"
@@ -34,17 +36,17 @@ func main() {
3436 sigChan := make (chan os.Signal , 1 )
3537 signal .Notify (sigChan , syscall .SIGINT , syscall .SIGTERM , syscall .SIGQUIT )
3638
39+ ctx , cancel := context .WithCancel (context .Background ())
40+ defer cancel ()
41+
3742 // start scheduler
38- go internal .StartScheduler (sigChan )
43+ go internal .StartScheduler (ctx )
3944
4045 go func () {
4146 sig := <- sigChan
47+ ctx .Done ()
4248 log .Println ("exit requested, shutting down" , "signal" , sig )
43- err = router .Shutdown ()
44- if err != nil {
45- log .Fatalln (err )
46- }
47- log .Println ("server shutdown" )
49+ router .ShutdownWithTimeout (time .Second )
4850 }()
4951
5052 err = router .Listen (fmt .Sprintf (":%d" , internal .AppCnf .Port ))
You can’t perform that action at this time.
0 commit comments