mirror of
https://github.com/kataras/iris.git
synced 2025-02-02 15:30:36 +01:00
c4f5fae561
Former-commit-id: bd5463a169a36b078dba1c1b6e7dd3ffbd627617
31 lines
902 B
Go
31 lines
902 B
Go
// Copyright 2017 Gerasimos Maropoulos, ΓΜ. All rights reserved.
|
|
// Use of this source code is governed by a BSD-style
|
|
// license that can be found in the LICENSE file.
|
|
|
|
package host
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
)
|
|
|
|
// OnInterrupt is a built'n supervisor task type which fires its
|
|
// value(Task) when an OS interrupt/kill signal received.
|
|
type OnInterrupt TaskRunnerFunc
|
|
|
|
// Run runs the interrupt task and completes the TaskRunner interface.
|
|
func (t OnInterrupt) Run(proc TaskProcess) {
|
|
t(proc)
|
|
}
|
|
|
|
// ShutdownOnInterruptTask returns a supervisor's built'n task which
|
|
// shutdowns the server when InterruptSignalTask fire this task.
|
|
func ShutdownOnInterruptTask(shutdownTimeout time.Duration) TaskRunner {
|
|
return OnInterrupt(func(proc TaskProcess) {
|
|
ctx, cancel := context.WithTimeout(context.TODO(), shutdownTimeout)
|
|
defer cancel()
|
|
proc.Host().Shutdown(ctx)
|
|
proc.Host().RestoreFlow()
|
|
})
|
|
}
|