summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-02-02 19:17:03 +0300
committerValery Piashchynski <[email protected]>2021-02-02 19:17:03 +0300
commit2bdf7fafa73cabf7cf63657a6b58f2a423ae0fcd (patch)
treefe5efc14a18f78218816a2bc7a2e19ee95642714 /internal
parent68becf8c58daec426f94513cf444061c199194d7 (diff)
Move worker states out of internal
Diffstat (limited to 'internal')
-rwxr-xr-xinternal/state.go46
-rwxr-xr-xinternal/state_test.go21
2 files changed, 20 insertions, 47 deletions
diff --git a/internal/state.go b/internal/state.go
index a14a6937..d208aeed 100755
--- a/internal/state.go
+++ b/internal/state.go
@@ -3,6 +3,8 @@ package internal
import (
"fmt"
"sync/atomic"
+
+ "github.com/spiral/roadrunner/v2/pkg/states"
)
// State represents WorkerProcess status and updated time.
@@ -24,36 +26,6 @@ type State interface {
LastUsed() uint64
}
-const (
- // StateInactive - no associated process
- StateInactive int64 = iota
-
- // StateReady - ready for job.
- StateReady
-
- // StateWorking - working on given payload.
- StateWorking
-
- // StateInvalid - indicates that WorkerProcess is being disabled and will be removed.
- StateInvalid
-
- // StateStopping - process is being softly stopped.
- StateStopping
-
- StateKilling
-
- // State of worker, when no need to allocate new one
- StateDestroyed
-
- // StateStopped - process has been terminated.
- StateStopped
-
- // StateErrored - error WorkerState (can't be used).
- StateErrored
-
- StateRemove
-)
-
type WorkerState struct {
value int64
numExecs uint64
@@ -69,17 +41,17 @@ func NewWorkerState(value int64) *WorkerState {
// String returns current WorkerState as string.
func (s *WorkerState) String() string {
switch s.Value() {
- case StateInactive:
+ case states.StateInactive:
return "inactive"
- case StateReady:
+ case states.StateReady:
return "ready"
- case StateWorking:
+ case states.StateWorking:
return "working"
- case StateInvalid:
+ case states.StateInvalid:
return "invalid"
- case StateStopped:
+ case states.StateStopped:
return "stopped"
- case StateErrored:
+ case states.StateErrored:
return "errored"
}
@@ -99,7 +71,7 @@ func (s *WorkerState) Value() int64 {
// IsActive returns true if WorkerProcess not Inactive or Stopped
func (s *WorkerState) IsActive() bool {
val := s.Value()
- return val == StateWorking || val == StateReady
+ return val == states.StateWorking || val == states.StateReady
}
// change WorkerState value (status)
diff --git a/internal/state_test.go b/internal/state_test.go
index bdb05825..a0581d57 100755
--- a/internal/state_test.go
+++ b/internal/state_test.go
@@ -3,25 +3,26 @@ package internal
import (
"testing"
+ "github.com/spiral/roadrunner/v2/pkg/states"
"github.com/stretchr/testify/assert"
)
func Test_NewState(t *testing.T) {
- st := NewWorkerState(StateErrored)
+ st := NewWorkerState(states.StateErrored)
assert.Equal(t, "errored", st.String())
- assert.Equal(t, "inactive", NewWorkerState(StateInactive).String())
- assert.Equal(t, "ready", NewWorkerState(StateReady).String())
- assert.Equal(t, "working", NewWorkerState(StateWorking).String())
- assert.Equal(t, "stopped", NewWorkerState(StateStopped).String())
+ assert.Equal(t, "inactive", NewWorkerState(states.StateInactive).String())
+ assert.Equal(t, "ready", NewWorkerState(states.StateReady).String())
+ assert.Equal(t, "working", NewWorkerState(states.StateWorking).String())
+ assert.Equal(t, "stopped", NewWorkerState(states.StateStopped).String())
assert.Equal(t, "undefined", NewWorkerState(1000).String())
}
func Test_IsActive(t *testing.T) {
- assert.False(t, NewWorkerState(StateInactive).IsActive())
- assert.True(t, NewWorkerState(StateReady).IsActive())
- assert.True(t, NewWorkerState(StateWorking).IsActive())
- assert.False(t, NewWorkerState(StateStopped).IsActive())
- assert.False(t, NewWorkerState(StateErrored).IsActive())
+ assert.False(t, NewWorkerState(states.StateInactive).IsActive())
+ assert.True(t, NewWorkerState(states.StateReady).IsActive())
+ assert.True(t, NewWorkerState(states.StateWorking).IsActive())
+ assert.False(t, NewWorkerState(states.StateStopped).IsActive())
+ assert.False(t, NewWorkerState(states.StateErrored).IsActive())
}