diff options
author | Neil Alexander <neilalexander@users.noreply.github.com> | 2022-03-25 12:24:21 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-25 12:24:21 +0000 |
commit | e6d4bdeed5a05f26677f81c02f7a43c84a4a947e (patch) | |
tree | d82d880e797695d48090ffe6423d2759d4413c0b /setup/process | |
parent | 5e780d3ca232af08079c7bebb6166519dda1906c (diff) |
Try to recover from corrupted NATS streams in memory temporarily (#2301)
Diffstat (limited to 'setup/process')
-rw-r--r-- | setup/process/process.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/setup/process/process.go b/setup/process/process.go index d55751d7..01eb26e2 100644 --- a/setup/process/process.go +++ b/setup/process/process.go @@ -2,13 +2,19 @@ package process import ( "context" + "fmt" "sync" + + "github.com/getsentry/sentry-go" + "github.com/sirupsen/logrus" + "go.uber.org/atomic" ) type ProcessContext struct { wg *sync.WaitGroup // used to wait for components to shutdown ctx context.Context // cancelled when Stop is called shutdown context.CancelFunc // shut down Dendrite + degraded atomic.Bool } func NewProcessContext() *ProcessContext { @@ -43,3 +49,14 @@ func (b *ProcessContext) WaitForShutdown() <-chan struct{} { func (b *ProcessContext) WaitForComponentsToFinish() { b.wg.Wait() } + +func (b *ProcessContext) Degraded() { + if b.degraded.CAS(false, true) { + logrus.Warn("Dendrite is running in a degraded state") + sentry.CaptureException(fmt.Errorf("Process is running in a degraded state")) + } +} + +func (b *ProcessContext) IsDegraded() bool { + return b.degraded.Load() +} |