-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Plakhotnikov Vladimir <embargo2710@gmail.com>
- Loading branch information
Showing
1 changed file
with
48 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |