Skip to content

Commit

Permalink
Shutdown not available in 1.7 #161
Browse files Browse the repository at this point in the history
On go 1.7 we will use Close() which will just kill the connection. It's
highly recommened that you use 1.8 or later, so that there is a graceful
shutdown.
  • Loading branch information
gdey committed Feb 15, 2018
1 parent 487c589 commit 6204ebf
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 9 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,3 @@
.idea
documents
*.toml
tegola
2 changes: 2 additions & 0 deletions cmd/tegola/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ tegola
static/debug
static/landuse2
*.log
*.zip
configs
osm_tools
log.txt

9 changes: 1 addition & 8 deletions cmd/tegola/cmd/server.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package cmd

import (
"context"
"time"

gdcmd "github.com/gdey/cmd"
"github.com/spf13/cobra"
"github.com/terranodo/tegola/provider"
Expand Down Expand Up @@ -46,11 +43,7 @@ var serverCmd = &cobra.Command{

// start our webserver
srv := server.Start(serverPort)
gdcmd.OnComplete(func() {
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel() // releases resources if slowOperation completes before timeout elapses
srv.Shutdown(ctx)
})
shutdown(srv)
<-gdcmd.Cancelled()
gdcmd.Complete()

Expand Down
20 changes: 20 additions & 0 deletions cmd/tegola/cmd/server_shutdown.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// +build go1.8

package cmd

import (
"context"
"net/http"
"time"

gdcmd "github.com/gdey/cmd"
)

func shutdown(srv *http.Server) {
gdcmd.OnComplete(func() {
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel() // releases resources if slowOperation completes before timeout elapses
srv.Shutdown(ctx)
})

}
20 changes: 20 additions & 0 deletions cmd/tegola/cmd/server_shutdown_1.7.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// +build !go1.8

package cmd

import (
"context"
"net/http"
"time"

gdcmd "github.com/gdey/cmd"
)

func shutdown(srv *http.Server) {
gdcmd.OnComplete(func() {
ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond)
defer cancel() // releases resources if slowOperation completes before timeout elapses
srv.Close()
})

}
2 changes: 2 additions & 0 deletions cmd/xyz2svg/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,5 @@ svg_files/*
configs
configs/*
_svg_files/*
_*
log.txt

0 comments on commit 6204ebf

Please sign in to comment.