Update StateChangeHandler for stacktrace changes
This commit is contained in:
parent
74a54da6f1
commit
7bafd82dde
@ -444,7 +444,7 @@ func (svc *session) logPending() {
|
||||
|
||||
// stateChangeHandler keeps track of session status changes and frequently stores session into db
|
||||
func (svc *session) stateChangeHandler(ctx context.Context) wfexec.StateChangeHandler {
|
||||
return func(i wfexec.SessionStatus, state *wfexec.State, s *wfexec.Session) {
|
||||
return func(status wfexec.SessionStatus, state *wfexec.State, s *wfexec.Session) {
|
||||
svc.mux.Lock()
|
||||
defer svc.mux.Unlock()
|
||||
|
||||
@ -459,6 +459,8 @@ func (svc *session) stateChangeHandler(ctx context.Context) wfexec.StateChangeHa
|
||||
return
|
||||
}
|
||||
|
||||
ses.FlushCounter++
|
||||
|
||||
log = log.With(logger.Uint64("workflowID", ses.WorkflowID))
|
||||
|
||||
log.Debug("state change handler")
|
||||
@ -482,7 +484,7 @@ func (svc *session) stateChangeHandler(ctx context.Context) wfexec.StateChangeHa
|
||||
|
||||
ses.AppendRuntimeStacktrace(frame)
|
||||
|
||||
switch i {
|
||||
switch status {
|
||||
case wfexec.SessionPrompted:
|
||||
ses.SuspendedAt = now()
|
||||
ses.Status = types.SessionPrompted
|
||||
@ -529,16 +531,16 @@ func (svc *session) stateChangeHandler(ctx context.Context) wfexec.StateChangeHa
|
||||
ses.Status = types.SessionCanceled
|
||||
|
||||
default:
|
||||
// force update on every F new frames (F=sessionStateFlushFrequency) but only when stacktrace is not nil
|
||||
update = ses.RuntimeStacktrace != nil && len(ses.RuntimeStacktrace)%sessionStateFlushFrequency == 0
|
||||
}
|
||||
|
||||
if !update {
|
||||
return
|
||||
// force update every X iterations
|
||||
update = ses.FlushCounter >= sessionStateFlushFrequency
|
||||
if !update {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
// Reset the counter whenever we flush due to whatever scenario
|
||||
ses.FlushCounter = 0
|
||||
ses.CopyRuntimeStacktrace()
|
||||
|
||||
if err := store.UpsertAutomationSession(ctx, svc.store, ses); err != nil {
|
||||
log.Error("failed to update session", zap.Error(err))
|
||||
}
|
||||
|
||||
@ -58,6 +58,12 @@ type (
|
||||
// the whole stacktrace
|
||||
RuntimeStacktrace Stacktrace `json:"-"`
|
||||
|
||||
// FlushCounter helps us keep track of when we should forcefully flush
|
||||
// the session to the database.
|
||||
//
|
||||
// This is required due to the change in exec stack traces.
|
||||
FlushCounter int `json:"-"`
|
||||
|
||||
l sync.RWMutex
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user