Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.

Commit

Permalink
starting work on gae support #213
Browse files Browse the repository at this point in the history
  • Loading branch information
markbates committed Jul 27, 2017
1 parent 71a39e4 commit 8481da3
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 65 deletions.
68 changes: 3 additions & 65 deletions app.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
package buffalo

import (
"fmt"
"net/http"
"os"
"os/signal"
"strings"
"sync"
"syscall"

gcontext "github.com/gorilla/context"
"github.com/gorilla/mux"
"github.com/markbates/refresh/refresh/web"
"github.com/pkg/errors"
)

Expand All @@ -30,62 +24,6 @@ type App struct {
children []*App
}

// Start the application at the specified address/port and listen for OS
// interrupt and kill signals and will attempt to stop the application
// gracefully. This will also start the Worker process, unless WorkerOff is enabled.
func (a *App) Start(addr string) error {
if !strings.Contains(addr, ":") {
addr = fmt.Sprintf(":%s", addr)
}
fmt.Printf("Starting application at %s\n", addr)
server := http.Server{
Addr: addr,
Handler: a,
}

go func() {
// gracefully shut down the application when the context is cancelled
<-a.Context.Done()
fmt.Println("Shutting down application")
err := server.Shutdown(a.Context)
if err != nil {
a.Logger.Error(errors.WithStack(err))
}
if !a.WorkerOff {
// stop the workers
err = a.Worker.Stop()
if err != nil {
a.Logger.Error(errors.WithStack(err))
}
}
}()

// if configured to do so, start the workers
if !a.WorkerOff {
go func() {
err := a.Worker.Start(a.Context)
if err != nil {
a.Stop(errors.WithStack(err))
}
}()
}

// listen for system signals, like CTRL-C
go func() {
signalChan := make(chan os.Signal, 1)
signal.Notify(signalChan, os.Interrupt, syscall.SIGTERM)
<-signalChan
a.Stop(nil)
}()

// start the web server
err := server.ListenAndServe()
if err != nil {
return a.Stop(errors.WithStack(err))
}
return nil
}

// Stop the application and attempt to gracefully shutdown
func (a *App) Stop(err error) error {
a.cancel()
Expand All @@ -106,9 +44,9 @@ func (a *App) ServeHTTP(w http.ResponseWriter, r *http.Request) {
}
var h http.Handler
h = a.router
if a.Env == "development" {
h = web.ErrorChecker(h)
}
// if a.Env == "development" {
// h = web.ErrorChecker(h)
// }
h.ServeHTTP(ws, r)
}

Expand Down
2 changes: 2 additions & 0 deletions buffalo/cmd/dev.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !appengine

package cmd

import (
Expand Down
2 changes: 2 additions & 0 deletions generators/newapp/new.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !appengine

package newapp

import (
Expand Down
2 changes: 2 additions & 0 deletions generators/refresh/refresh.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !appengine

package refresh

import (
Expand Down
2 changes: 2 additions & 0 deletions grifts/shoulders.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// +build !appengine

package grifts

import (
Expand Down

0 comments on commit 8481da3

Please sign in to comment.