yangwwei commented on pull request #230: URL: https://github.com/apache/incubator-yunikorn-core/pull/230#issuecomment-755833895
hi @kingamarton thanks for the update. I think this can work, but we maybe able to improve this further. The idea is to abstract the common things into a struct, something like: We can define a `StateTimers` and `StateTimer` type like the following: ``` type StateTimers map[applicationState]StateTimer type StateTimer struct { timeout time.Duration callback func() // executes when it times out } func (s *StateTimer) Start() {} func (s *StateTimer) Stop() {} ``` then we can init the stateTimers in each app like ``` Application{ ... stateTimers : StateTimers{ Waiting : { timeout: 3*time.Second, callback: func() { // do something }, }, } } ``` and then in the state machine, we can simplify the code to something like: ``` // this gets executed in every state transition fsm.Callbacks{ "enter_state": func(event *fsm.Event) { // blablabla... if st, ok := stateTimers[currentState]; ok { // a state timer was set st.start() } }, } ``` similarly to the "leave_state" callbacks. If we can do this, this can be further utilized by other state machines, which gives us a general way to handle state timeouts. Do you think this makes sense to you? ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org