From efcddcc8d1b676c64cbd41a5f645bd046ba416d7 Mon Sep 17 00:00:00 2001 From: Wolfy-J Date: Mon, 11 Jun 2018 12:13:36 +0300 Subject: no more updated --- cmd/rr/main.go | 10 ---------- service/http/rpc.go | 4 ---- state.go | 13 +------------ state_test.go | 1 - worker_test.go | 19 +------------------ 5 files changed, 2 insertions(+), 45 deletions(-) diff --git a/cmd/rr/main.go b/cmd/rr/main.go index 07448feb..470e4795 100644 --- a/cmd/rr/main.go +++ b/cmd/rr/main.go @@ -36,23 +36,13 @@ import ( "github.com/spf13/cobra" _ "net/http/pprof" - "os" "log" - "runtime/pprof" "net/http" ) var debugMode bool func main() { - f, err := os.Create("cpu.pprof") - if err != nil { - log.Fatal(err) - } - - pprof.StartCPUProfile(f) - defer pprof.StopCPUProfile() - go func() { log.Println(http.ListenAndServe("localhost:6060", nil)) }() diff --git a/service/http/rpc.go b/service/http/rpc.go index 2adb8706..aa68a826 100644 --- a/service/http/rpc.go +++ b/service/http/rpc.go @@ -25,9 +25,6 @@ type Worker struct { // Created is unix nano timestamp of worker creation time. Created int64 `json:"created"` - - // Updated is unix nano timestamp of last worker execution. - Updated int64 `json:"updated"` } // Reset resets underlying RR worker pool and restarts all of it's workers. @@ -53,7 +50,6 @@ func (rpc *rpcServer) Workers(list bool, r *WorkerList) error { Status: state.String(), NumJobs: state.NumExecs(), Created: w.Created.UnixNano(), - Updated: state.Updated().UnixNano(), }) } diff --git a/state.go b/state.go index 61e48231..4a1a8384 100644 --- a/state.go +++ b/state.go @@ -3,7 +3,6 @@ package roadrunner import ( "fmt" "sync/atomic" - "time" ) // State represents worker status and updated time. @@ -15,9 +14,6 @@ type State interface { // NumJobs shows how many times worker was invoked NumExecs() int64 - - // Updated indicates a moment updated last state change - Updated() time.Time } const ( @@ -43,11 +39,10 @@ const ( type state struct { value int64 numExecs int64 - updated int64 } func newState(value int64) *state { - return &state{value: value, updated: time.Now().UnixNano()} + return &state{value: value} } // String returns current state as string. @@ -79,11 +74,6 @@ func (s *state) IsActive() bool { return state == StateWorking || state == StateReady } -// Updated indicates a moment updated last state change -func (s *state) Updated() time.Time { - return time.Unix(0, atomic.LoadInt64(&s.updated)) -} - func (s *state) NumExecs() int64 { return atomic.LoadInt64(&s.numExecs) } @@ -91,7 +81,6 @@ func (s *state) NumExecs() int64 { // change state value (status) func (s *state) set(value int64) { atomic.StoreInt64(&s.value, value) - atomic.StoreInt64(&s.updated, time.Now().UnixNano()) } // register new execution atomically diff --git a/state_test.go b/state_test.go index be63230e..c13c5a88 100644 --- a/state_test.go +++ b/state_test.go @@ -9,7 +9,6 @@ func Test_NewState(t *testing.T) { st := newState(StateErrored) assert.Equal(t, "errored", st.String()) - assert.NotEqual(t, 0, st.Updated().Unix()) assert.Equal(t, "inactive", newState(StateInactive).String()) assert.Equal(t, "ready", newState(StateReady).String()) diff --git a/worker_test.go b/worker_test.go index 6e65c998..2e3bc111 100644 --- a/worker_test.go +++ b/worker_test.go @@ -4,7 +4,6 @@ import ( "github.com/stretchr/testify/assert" "os/exec" "testing" - "time" ) func Test_GetState(t *testing.T) { @@ -191,20 +190,4 @@ func Test_NumExecs(t *testing.T) { w.Exec(&Payload{Body: []byte("hello")}) assert.Equal(t, int64(3), w.State().NumExecs()) -} - -func Test_StateUpdated(t *testing.T) { - cmd := exec.Command("php", "php-src/tests/client.php", "echo", "pipes") - - w, _ := NewPipeFactory().SpawnWorker(cmd) - go func() { - assert.NoError(t, w.Wait()) - }() - defer w.Stop() - - tm := time.Now() - time.Sleep(time.Millisecond) - - w.Exec(&Payload{Body: []byte("hello")}) - assert.True(t, w.State().Updated().After(tm)) -} +} \ No newline at end of file -- cgit v1.2.3