func main() { if _, err := parser.Parse(); err != nil { fmt.Fprintln(os.Stderr, err) if _, ok := err.(*flags.Error); !ok { logger.Debugf("%v failed: %v", os.Args, err) } os.Exit(1) } }
func logit(handler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ww := &wrappedWriter{w: w} t0 := time.Now() handler.ServeHTTP(ww, r) t := time.Now().Sub(t0) logger.Debugf("%s %s %s %s %d", r.RemoteAddr, r.Method, r.URL, t, ww.s) }) }
// Ensure starts new goroutines for all known tasks with no pending // dependencies. // Note that Ensure will lock the state. func (r *TaskRunner) Ensure() { r.mu.Lock() defer r.mu.Unlock() if r.stopped { // we are stopping, don't run another ensure return } // Locks must be acquired in the same order everywhere. r.state.Lock() defer r.state.Unlock() for _, t := range r.state.Tasks() { handlers, ok := r.handlers[t.Kind()] if !ok { // Handled by a different runner instance. continue } tb := r.tombs[t.ID()] if t.Status() == AbortStatus { if tb != nil { tb.Kill(nil) continue } r.tryUndo(t) } if tb != nil { // Already being handled. continue } status := t.Status() if status.Ready() { continue } if status == UndoStatus && handlers.undo == nil { // Cannot undo. Revert to done status. t.SetStatus(DoneStatus) if len(t.WaitTasks()) > 0 { r.state.EnsureBefore(0) } continue } if mustWait(t) { // Dependencies still unhandled. continue } logger.Debugf("Running task %s on %s: %s", t.ID(), t.Status(), t.Summary()) r.run(t) } }
func run() error { _, err := parser.Parse() if err != nil { return err } if _, ok := err.(*flags.Error); !ok { logger.Debugf("cannot parse arguments: %v: %v", os.Args, err) } return nil }
func (t *Task) addLog(kind, format string, args []interface{}) { if len(t.log) > 9 { copy(t.log, t.log[len(t.log)-9:]) t.log = t.log[:9] } tstr := timeNow().Format(time.RFC3339) msg := fmt.Sprintf(tstr+" "+kind+" "+format, args...) t.log = append(t.log, msg) logger.Debugf(msg) }
func logit(handler http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { ww := &wrappedWriter{w: w} t0 := time.Now() handler.ServeHTTP(ww, r) t := time.Now().Sub(t0) url := r.URL.String() if !strings.Contains(url, "/changes/") { logger.Debugf("%s %s %s %s %d", r.RemoteAddr, r.Method, r.URL, t, ww.s) } }) }
func (d *Daemon) addRoutes() { d.router = mux.NewRouter() for _, c := range api { c.d = d logger.Debugf("adding %s", c.Path) d.router.Handle(c.Path, c).Name(c.Path) } // also maybe add a /favicon.ico handler... d.router.NotFoundHandler = NotFound }
func main() { if _, err := parser.Parse(); err != nil { if err == priv.ErrNeedRoot { // make the generic root error more specific for // the CLI user. err = snappy.ErrNeedRoot } fmt.Fprintln(os.Stderr, err) if _, ok := err.(*flags.Error); !ok { logger.Debugf("%v failed: %v", os.Args, err) } os.Exit(1) } }
// Init sets up the Daemon's internal workings. // Don't call more than once. func (d *Daemon) Init() error { t0 := time.Now() listeners, err := activation.Listeners(false) if err != nil { return err } if len(listeners) != 1 { return fmt.Errorf("daemon does not handle %d listeners right now, just one", len(listeners)) } d.listener = listeners[0] d.addRoutes() logger.Debugf("init done in %s", time.Now().Sub(t0)) return nil }