forked from roadrunner-server/http
-
Notifications
You must be signed in to change notification settings - Fork 0
/
status.go
50 lines (42 loc) · 1.11 KB
/
status.go
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
package http
import (
"net/http"
"github.com/roadrunner-server/api/v4/plugins/v1/status"
"github.com/roadrunner-server/sdk/v4/fsm"
)
// Status return status of the particular plugin
func (p *Plugin) Status() (*status.Status, error) {
p.mu.RLock()
defer p.mu.RUnlock()
workers := p.pool.Workers()
for i := 0; i < len(workers); i++ {
if workers[i].State().IsActive() {
return &status.Status{
Code: http.StatusOK,
}, nil
}
}
// if there are no workers, threat this as error
return &status.Status{
Code: http.StatusServiceUnavailable,
}, nil
}
// Ready return readiness status of the particular plugin
func (p *Plugin) Ready() (*status.Status, error) {
p.mu.RLock()
defer p.mu.RUnlock()
workers := p.pool.Workers()
for i := 0; i < len(workers); i++ {
// If state of the worker is ready (at least 1)
// we assume, that plugin's worker pool is ready
if workers[i].State().Compare(fsm.StateReady) {
return &status.Status{
Code: http.StatusOK,
}, nil
}
}
// if there are no workers, threat this as no content error
return &status.Status{
Code: http.StatusServiceUnavailable,
}, nil
}