File size: 1,505 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package app

import (
	"io"
	"net/http"

	"github.com/google/uuid"
	"github.com/target/goalert/app/lifecycle"
	"github.com/target/goalert/util/errutil"
)

func (app *App) healthCheck(w http.ResponseWriter, req *http.Request) {
	if app.mgr.Status() == lifecycle.StatusShutdown {
		http.Error(w, "server shutting down", http.StatusInternalServerError)
		return
	}
	if app.mgr.Status() == lifecycle.StatusStarting {
		http.Error(w, "server starting", http.StatusInternalServerError)
		return
	}

	// Good to go
}

func (app *App) engineStatus(w http.ResponseWriter, req *http.Request) {
	if app.mgr.Status() == lifecycle.StatusShutdown {
		http.Error(w, "server shutting down", http.StatusInternalServerError)
		return
	}

	if app.cfg.APIOnly {
		http.Error(w, "engine not running", http.StatusInternalServerError)
		return
	}

	var id uuid.UUID
	if nStr := req.FormValue("id"); nStr != "" {
		_id, err := uuid.Parse(nStr)
		if err != nil {
			http.Error(w, "invalid id", http.StatusBadRequest)
			return
		}
		id = _id
	} else {
		id = app.Engine.NextCycleID()
	}

	errutil.HTTPError(req.Context(), w, app.Engine.WaitCycleID(req.Context(), id))
}

func (app *App) engineCycle(w http.ResponseWriter, req *http.Request) {
	if app.mgr.Status() == lifecycle.StatusShutdown {
		http.Error(w, "server shutting down", http.StatusBadRequest)
		return
	}

	if app.cfg.APIOnly {
		http.Error(w, "engine not running", http.StatusBadRequest)
		return
	}

	_, _ = io.WriteString(w, app.Engine.NextCycleID().String())

}