mirror of
https://mau.dev/mautrix/go.git
synced 2026-03-14 14:25:53 +01:00
bridgev2: add flag to indicate when bridge is stopping
This commit is contained in:
parent
19ed3ac40b
commit
7b33248d3d
1 changed files with 10 additions and 0 deletions
|
|
@ -11,6 +11,7 @@ import (
|
|||
"fmt"
|
||||
"os"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
"time"
|
||||
|
||||
"github.com/rs/zerolog"
|
||||
|
|
@ -52,6 +53,7 @@ type Bridge struct {
|
|||
|
||||
Background bool
|
||||
ExternallyManagedDB bool
|
||||
stopping atomic.Bool
|
||||
|
||||
wakeupBackfillQueue chan struct{}
|
||||
stopBackfillQueue *exsync.Event
|
||||
|
|
@ -127,6 +129,7 @@ func (br *Bridge) Start(ctx context.Context) error {
|
|||
|
||||
func (br *Bridge) RunOnce(ctx context.Context, loginID networkid.UserLoginID, params *ConnectBackgroundParams) error {
|
||||
br.Background = true
|
||||
br.stopping.Store(false)
|
||||
err := br.StartConnectors(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
@ -162,6 +165,7 @@ func (br *Bridge) RunOnce(ctx context.Context, loginID networkid.UserLoginID, pa
|
|||
case <-time.After(20 * time.Second):
|
||||
case <-ctx.Done():
|
||||
}
|
||||
br.stopping.Store(true)
|
||||
return nil
|
||||
} else {
|
||||
br.Log.Info().Str("user_login_id", string(login.ID)).Msg("Starting individual user login in background mode")
|
||||
|
|
@ -171,6 +175,7 @@ func (br *Bridge) RunOnce(ctx context.Context, loginID networkid.UserLoginID, pa
|
|||
|
||||
func (br *Bridge) StartConnectors(ctx context.Context) error {
|
||||
br.Log.Info().Msg("Starting bridge")
|
||||
br.stopping.Store(false)
|
||||
if br.BackgroundCtx == nil || br.BackgroundCtx.Err() != nil {
|
||||
br.BackgroundCtx, br.cancelBackgroundCtx = context.WithCancel(context.Background())
|
||||
br.BackgroundCtx = br.Log.WithContext(br.BackgroundCtx)
|
||||
|
|
@ -368,6 +373,10 @@ func (br *Bridge) StartLogins(ctx context.Context) error {
|
|||
return nil
|
||||
}
|
||||
|
||||
func (br *Bridge) IsStopping() bool {
|
||||
return br.stopping.Load()
|
||||
}
|
||||
|
||||
func (br *Bridge) Stop() {
|
||||
br.stop(false, 0)
|
||||
}
|
||||
|
|
@ -378,6 +387,7 @@ func (br *Bridge) StopWithTimeout(timeout time.Duration) {
|
|||
|
||||
func (br *Bridge) stop(isRunOnce bool, timeout time.Duration) {
|
||||
br.Log.Info().Msg("Shutting down bridge")
|
||||
br.stopping.Store(true)
|
||||
br.DisappearLoop.Stop()
|
||||
br.stopBackfillQueue.Set()
|
||||
br.Matrix.PreStop()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue