-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #201 from porters-xyz/graceful_shutdown
Adds graceful shutdown for proxy server and task queue
- Loading branch information
Showing
5 changed files
with
88 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package common | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
// store config as constants for now | ||
const ( | ||
SHUTDOWN_DELAY = 5 * time.Second | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"os" | ||
"os/signal" | ||
"sync" | ||
"syscall" | ||
|
||
"porters/common" | ||
"porters/proxy" | ||
) | ||
|
||
func gateway() { | ||
// Start job queue | ||
common.GetTaskQueue().SetupWorkers() | ||
|
||
log.Println("starting gateway") | ||
proxy.Start() | ||
|
||
done := make(chan os.Signal) | ||
signal.Notify(done, syscall.SIGINT, syscall.SIGTERM) | ||
<-done | ||
shutdown() | ||
} | ||
|
||
func shutdown() { | ||
var wg sync.WaitGroup | ||
|
||
wg.Add(2) | ||
go func() { | ||
defer wg.Done() | ||
proxy.Stop() | ||
}() | ||
go func() { | ||
defer wg.Done() | ||
common.GetTaskQueue().CloseQueue() | ||
}() | ||
wg.Wait() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters