Skip to content
Snippets Groups Projects
Commit 874d48f8 authored by Manuel Kieweg's avatar Manuel Kieweg
Browse files

move ticker creation to commit

parent 7edb4dc1
No related branches found
No related tags found
9 merge requests!246Develop,!245Develop into Master,!244Master into develop2 into master,!219Draft: Testing,!214Test pipelines,!195DO NOT MERGE 2,!194DO NOT MERGE! just for testing,!188move ticker creation to commit,!138Develop
...@@ -117,26 +117,27 @@ func stateManager(ch *Change, timeout time.Duration) (chan<- ppb.Change_State, < ...@@ -117,26 +117,27 @@ func stateManager(ch *Change, timeout time.Duration) (chan<- ppb.Change_State, <
stateOut := make(chan ppb.Change_State) stateOut := make(chan ppb.Change_State)
stateRequest := make(chan bool) stateRequest := make(chan bool)
errChan := make(chan error) errChan := make(chan error)
ticker := time.NewTicker(timeout) // create ticker and make it wait for 1 week
// workaround for delayed ticker start and ugly housekeeping
ticker := time.NewTicker(time.Hour * 7 * 24)
go func() { go func() {
state := ppb.Change_PENDING state := ppb.Change_PENDING
for { for {
select { select {
case <-ticker.C: case <-ticker.C:
// only roll back committed changes err := ch.callback(ch.intendedState, ch.previousState)
if state == ppb.Change_COMMITTED { if err != nil {
err := ch.callback(ch.intendedState, ch.previousState) state = ppb.Change_INCONSISTENT
if err != nil { errChan <- err
state = ppb.Change_INCONSISTENT
errChan <- err
}
errChan <- fmt.Errorf("change %v timed out", ch.cuid)
break
} }
errChan <- fmt.Errorf("change %v timed out", ch.cuid)
break
case s := <-stateIn: case s := <-stateIn:
switch s { switch s {
case ppb.Change_COMMITTED: case ppb.Change_COMMITTED:
// reset ticker to enable activate the change timeout
ticker.Reset(timeout)
err := ch.callback(ch.previousState, ch.intendedState) err := ch.callback(ch.previousState, ch.intendedState)
if err != nil { if err != nil {
state = ppb.Change_INCONSISTENT state = ppb.Change_INCONSISTENT
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment