summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorValery Piashchynski <[email protected]>2021-02-04 20:37:48 +0300
committerValery Piashchynski <[email protected]>2021-02-04 20:37:48 +0300
commitd629f08408a4478aaba90079a4e37ab69cfc12ef (patch)
tree2cb67bc5c9be295428239369e9d211f3888308fe /internal
parentefacb852e279e6bbfc076c0faff391ff39815718 (diff)
pre-rc stabilization of the interfaces and internal code
Diffstat (limited to 'internal')
-rwxr-xr-xinternal/state.go94
-rwxr-xr-xinternal/state_test.go28
2 files changed, 0 insertions, 122 deletions
diff --git a/internal/state.go b/internal/state.go
deleted file mode 100755
index d208aeed..00000000
--- a/internal/state.go
+++ /dev/null
@@ -1,94 +0,0 @@
-package internal
-
-import (
- "fmt"
- "sync/atomic"
-
- "github.com/spiral/roadrunner/v2/pkg/states"
-)
-
-// State represents WorkerProcess status and updated time.
-type State interface {
- fmt.Stringer
- // Value returns WorkerState value
- Value() int64
- // Set sets the WorkerState
- Set(value int64)
- // NumJobs shows how many times WorkerProcess was invoked
- NumExecs() uint64
- // IsActive returns true if WorkerProcess not Inactive or Stopped
- IsActive() bool
- // RegisterExec using to registering php executions
- RegisterExec()
- // SetLastUsed sets worker last used time
- SetLastUsed(lu uint64)
- // LastUsed return worker last used time
- LastUsed() uint64
-}
-
-type WorkerState struct {
- value int64
- numExecs uint64
- // to be lightweight, use UnixNano
- lastUsed uint64
-}
-
-// Thread safe
-func NewWorkerState(value int64) *WorkerState {
- return &WorkerState{value: value}
-}
-
-// String returns current WorkerState as string.
-func (s *WorkerState) String() string {
- switch s.Value() {
- case states.StateInactive:
- return "inactive"
- case states.StateReady:
- return "ready"
- case states.StateWorking:
- return "working"
- case states.StateInvalid:
- return "invalid"
- case states.StateStopped:
- return "stopped"
- case states.StateErrored:
- return "errored"
- }
-
- return "undefined"
-}
-
-// NumExecs returns number of registered WorkerProcess execs.
-func (s *WorkerState) NumExecs() uint64 {
- return atomic.LoadUint64(&s.numExecs)
-}
-
-// Value WorkerState returns WorkerState value
-func (s *WorkerState) Value() int64 {
- return atomic.LoadInt64(&s.value)
-}
-
-// IsActive returns true if WorkerProcess not Inactive or Stopped
-func (s *WorkerState) IsActive() bool {
- val := s.Value()
- return val == states.StateWorking || val == states.StateReady
-}
-
-// change WorkerState value (status)
-func (s *WorkerState) Set(value int64) {
- atomic.StoreInt64(&s.value, value)
-}
-
-// register new execution atomically
-func (s *WorkerState) RegisterExec() {
- atomic.AddUint64(&s.numExecs, 1)
-}
-
-// Update last used time
-func (s *WorkerState) SetLastUsed(lu uint64) {
- atomic.StoreUint64(&s.lastUsed, lu)
-}
-
-func (s *WorkerState) LastUsed() uint64 {
- return atomic.LoadUint64(&s.lastUsed)
-}
diff --git a/internal/state_test.go b/internal/state_test.go
deleted file mode 100755
index a0581d57..00000000
--- a/internal/state_test.go
+++ /dev/null
@@ -1,28 +0,0 @@
-package internal
-
-import (
- "testing"
-
- "github.com/spiral/roadrunner/v2/pkg/states"
- "github.com/stretchr/testify/assert"
-)
-
-func Test_NewState(t *testing.T) {
- st := NewWorkerState(states.StateErrored)
-
- assert.Equal(t, "errored", st.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(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())
-}