Compare commits
No commits in common. "641624ef3b2ce08b67ea75f4849d81a365fdbd8b" and "772e9ca29079a996617b2a121d4a2f944567fb46" have entirely different histories.
641624ef3b
...
772e9ca290
@ -1,27 +0,0 @@
|
|||||||
// Example broken demonstrates how the environment will forcibly kill the
|
|
||||||
// program if an actor cannot shut down.
|
|
||||||
package main
|
|
||||||
|
|
||||||
import "os"
|
|
||||||
import "log"
|
|
||||||
import "context"
|
|
||||||
import "git.tebibyte.media/sashakoshka/camfish"
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
camfish.Run("broken",
|
|
||||||
"Example broken demonstrates how the environment will " +
|
|
||||||
"forcibly kill the program if an actor cannot shut down",
|
|
||||||
new(broken))
|
|
||||||
}
|
|
||||||
|
|
||||||
// broken is an incorrectly implemented actor that cannot shut down.
|
|
||||||
type broken struct { }
|
|
||||||
var _ camfish.Runnable = new(broken)
|
|
||||||
func (this *broken) Type() string { return "broken" }
|
|
||||||
|
|
||||||
func (this *broken) Run(ctx context.Context) error {
|
|
||||||
log.Println("(i) [broken] wait for approximately 8 minutes")
|
|
||||||
log.Printf("(i) [broken] if impatient, run: kill -9 %d", os.Getpid())
|
|
||||||
<- (chan struct { })(nil)
|
|
||||||
return ctx.Err() // unreachable, of course
|
|
||||||
}
|
|
@ -42,7 +42,7 @@ func (this *httpServer) Init(ctx context.Context) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *httpServer) Run() error {
|
func (this *httpServer) Run() error {
|
||||||
log.Printf("(i) [http-server] listening on %s", this.server.Addr)
|
log.Printf("[http] listening on %s", this.server.Addr)
|
||||||
err := this.server.ListenAndServe()
|
err := this.server.ListenAndServe()
|
||||||
if errors.Is(err, http.ErrServerClosed) { return nil }
|
if errors.Is(err, http.ErrServerClosed) { return nil }
|
||||||
return err
|
return err
|
||||||
|
13
phases.go
13
phases.go
@ -255,19 +255,6 @@ func (this *environment) phase70_5Trimming() bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (this *environment) phase80Shutdown() bool {
|
func (this *environment) phase80Shutdown() bool {
|
||||||
ctx, done := context.WithTimeout(
|
|
||||||
context.Background(),
|
|
||||||
defaul(this.timing.shutdownTimeout.Load(), defaultShutdownTimeout))
|
|
||||||
defer done()
|
|
||||||
go func() {
|
|
||||||
<- ctx.Done()
|
|
||||||
if errors.Is(context.Cause(ctx), context.DeadlineExceeded) {
|
|
||||||
log.Println("XXX (80) shutdown timeout expired, performing emergency halt")
|
|
||||||
log.Printf("====== [%s] END =======", this.name)
|
|
||||||
os.Exit(1)
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
|
|
||||||
cause := context.Cause(this.ctx)
|
cause := context.Cause(this.ctx)
|
||||||
if cause != nil {
|
if cause != nil {
|
||||||
log.Println("XXX (80) shutting down because:", cause)
|
log.Println("XXX (80) shutting down because:", cause)
|
||||||
|
Loading…
Reference in New Issue
Block a user