Catch os.Interrupt signal with iris.PostInterrupt example added in comments.

https://github.com/iris-contrib/examples/tree/master/os_interrupt
This commit is contained in:
Gerasimos (Makis) Maropoulos 2017-01-11 18:01:29 +02:00
parent 5ad7c6e01f
commit 23f9ad13a1
3 changed files with 16 additions and 0 deletions

View File

@ -25,6 +25,8 @@ iris.Plugins.PostInterrupt(func(s *Framework){
```
- Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
## 6.0.7 -> 6.0.8
- Add `iris.UseTemplateFunc(functionName string, function interface{})`. You could always set custom template funcs by using each of [template engine's](https://github.com/kataras/go-template) configuration but this function will help newcomers to start creating their custom template funcs.

View File

@ -541,7 +541,9 @@ func (s *Framework) postServe() {
ch := make(chan os.Signal, 1)
signal.Notify(ch, os.Interrupt)
<-ch
// catch custom plugin event for interrupt
// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
s.Plugins.DoPostInterrupt(s)
if !s.Plugins.PostInterruptFired() {
// if no PostInterrupt events fired, then I assume that the user doesn't cares

View File

@ -96,11 +96,13 @@ type (
// graceful shutdown can be done here
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
PostInterrupt(*Framework)
}
// PostInterruptFunc implements the simple function listener for the PostInterrupt(*Framework)
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
PostInterruptFunc func(*Framework)
// pluginPreClose implements the PreClose(*Framework) method
@ -220,6 +222,15 @@ func (fn PostListenFunc) PostListen(station *Framework) {
fn(station)
}
// PostInterrupt it's being called only one time, when os.Interrupt system event catched
// graceful shutdown can be done here
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
func (fn PostInterruptFunc) PostInterrupt(station *Framework) {
fn(station)
}
// PreClose it's being called only one time, BEFORE the Iris .Close method
// any plugin cleanup/clear memory happens here
//
@ -540,6 +551,7 @@ func (p *pluginContainer) PostListenFired() bool {
// PostInterrupt adds a PostInterrupt plugin-function to the plugin flow container
//
// Read more here: https://github.com/kataras/iris/blob/master/HISTORY.md#608---609
// Example: https://github.com/iris-contrib/examples/tree/master/os_interrupt
func (p *pluginContainer) PostInterrupt(fn PostInterruptFunc) {
p.Add(fn)
}