Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: jobs workers status #81

Merged
merged 2 commits into from
Jun 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 48 additions & 0 deletions status.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package jobs

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.workersPool.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.workersPool.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
}