-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Simplify mq * Add QuitWorker * Update mq.go * Update mq.go * Update mq.go * Update mq.go * Update mq.go * Update mq.go * Add Bind queue * Update mq.go * Add message reject * Update mq.go * Remove Nack * Add ConsumerOptions * Update mq.go * Update mq.go * Update mq.go * Update mq.go * Update mq.go * Fix callback * Update mq.go * Add SetupGracefulShutdown * Add SetupGracefulShutdownForTimeout * Rename to SetupGracefulShutdown * Add StacktraceConfiguration
- Loading branch information
Showing
4 changed files
with
164 additions
and
37 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,43 @@ | ||
package gin | ||
|
||
import ( | ||
"context" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
|
||
"github.com/gin-gonic/gin" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func SetupGracefulShutdown(ctx context.Context, port string, engine *gin.Engine) { | ||
server := &http.Server{ | ||
Addr: ":" + port, | ||
Handler: engine, | ||
} | ||
|
||
defer func() { | ||
if err := server.Shutdown(ctx); err != nil { | ||
log.Info("Server Shutdown: ", err) | ||
} | ||
}() | ||
|
||
signalForExit := make(chan os.Signal, 1) | ||
signal.Notify(signalForExit, | ||
syscall.SIGHUP, | ||
syscall.SIGINT, | ||
syscall.SIGTERM, | ||
syscall.SIGQUIT) | ||
|
||
go func() { | ||
if err := server.ListenAndServe(); err != nil { | ||
log.Fatal("Application failed", err) | ||
} | ||
}() | ||
log.WithFields(log.Fields{"bind": port}).Info("Running application") | ||
|
||
stop := <-signalForExit | ||
log.Info("Stop signal Received", stop) | ||
log.Info("Waiting for all jobs to stop") | ||
} |
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,19 @@ | ||
package middleware | ||
|
||
import ( | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
func SetupGracefulShutdown(timeout time.Duration) { | ||
quit := make(chan os.Signal, 1) | ||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM) | ||
<-quit | ||
log.Info("Shutdown timeout: ...", timeout) | ||
time.Sleep(timeout) | ||
log.Info("Exiting gracefully") | ||
} |
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