fix: start system default sync channels by default
Create and restart paths enable IsSystemDefault channels; SyncPage auto-starts after save. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -73,7 +73,7 @@ func (s *FileStore) EnsureSystemDefaultChannel(opts DefaultChannelOpts) (Channel
|
||||
ch := Channel{
|
||||
TenantID: opts.TenantID,
|
||||
Name: name,
|
||||
Enabled: false, // 默认同步通道供 agent push 落点;不启本地 outbox 轮询
|
||||
Enabled: true, // 默认运行中:可收 agent push,并预热 remote
|
||||
Direction: DirLocalToRemote,
|
||||
ConflictPolicy: PolicyLWWSource,
|
||||
IsSystemDefault: true,
|
||||
@@ -107,3 +107,22 @@ func ResolveOnlineDBID(explicit, channelID string) string {
|
||||
}
|
||||
return strings.TrimSpace(channelID)
|
||||
}
|
||||
|
||||
// EnsureAndStartSystemDefaultChannel 创建/复用公司默认同步通道,并确保处于运行中(Enabled + runner)。
|
||||
func (m *Manager) EnsureAndStartSystemDefaultChannel(opts DefaultChannelOpts) (Channel, error) {
|
||||
if m == nil || m.store == nil {
|
||||
return Channel{}, fmt.Errorf("dbsync not enabled")
|
||||
}
|
||||
ch, err := m.store.EnsureSystemDefaultChannel(opts)
|
||||
if err != nil {
|
||||
return Channel{}, err
|
||||
}
|
||||
if err := m.StartChannel(ch.ID); err != nil {
|
||||
return ch, fmt.Errorf("start default channel: %w", err)
|
||||
}
|
||||
if updated, err := m.store.GetChannel(ch.ID); err == nil {
|
||||
return *updated, nil
|
||||
}
|
||||
ch.Enabled = true
|
||||
return ch, nil
|
||||
}
|
||||
|
||||
@@ -28,7 +28,8 @@ func (m *Manager) StartAll(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
for _, ch := range list {
|
||||
if ch.Enabled {
|
||||
// 公司默认同步通道默认运行中(即使历史记录曾为 Enabled=false)
|
||||
if ch.Enabled || ch.IsSystemDefault {
|
||||
_ = m.StartChannel(ch.ID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ func (l *AgentAdminLogic) ensureAgentSyncBind(acc *agentstore.Account) (*agentst
|
||||
if driver == "" {
|
||||
driver = dbsync.DriverPostgres
|
||||
}
|
||||
ch, err := l.svcCtx.DBSync.Store().EnsureSystemDefaultChannel(dbsync.DefaultChannelOpts{
|
||||
ch, err := l.svcCtx.DBSync.EnsureAndStartSystemDefaultChannel(dbsync.DefaultChannelOpts{
|
||||
TenantID: acc.TenantID,
|
||||
AgentID: acc.AgentID,
|
||||
Name: fmt.Sprintf("默认同步 · %s", acc.Name),
|
||||
|
||||
@@ -57,6 +57,7 @@ func (l *AuthLogic) CreateBindCode(req BindCodeCreateReq) (*bindcodestore.BindCo
|
||||
if online == "" {
|
||||
online = dbsync.ResolveOnlineDBID("", ch.ID)
|
||||
}
|
||||
_ = l.svcCtx.DBSync.StartChannel(ch.ID) // 已有默认同步通道也保持运行中
|
||||
} else {
|
||||
// 尝试创建默认同步通道
|
||||
cfg := l.svcCtx.Config.DBSync
|
||||
@@ -64,7 +65,7 @@ func (l *AuthLogic) CreateBindCode(req BindCodeCreateReq) (*bindcodestore.BindCo
|
||||
if driver == "" {
|
||||
driver = dbsync.DriverPostgres
|
||||
}
|
||||
saved, err := l.svcCtx.DBSync.Store().EnsureSystemDefaultChannel(dbsync.DefaultChannelOpts{
|
||||
saved, err := l.svcCtx.DBSync.EnsureAndStartSystemDefaultChannel(dbsync.DefaultChannelOpts{
|
||||
TenantID: tid,
|
||||
RemoteDriver: driver,
|
||||
RemoteDSN: strings.TrimSpace(cfg.DefaultRemoteDSN),
|
||||
|
||||
@@ -160,7 +160,7 @@ func (l *AuthLogic) bindUserHostSync(u *userstore.User, hostKey, name, localID,
|
||||
if driver == "" {
|
||||
driver = dbsync.DriverPostgres
|
||||
}
|
||||
ch, err := l.svcCtx.DBSync.Store().EnsureSystemDefaultChannel(dbsync.DefaultChannelOpts{
|
||||
ch, err := l.svcCtx.DBSync.EnsureAndStartSystemDefaultChannel(dbsync.DefaultChannelOpts{
|
||||
TenantID: u.TenantID,
|
||||
RemoteDriver: driver,
|
||||
RemoteDSN: strings.TrimSpace(cfg.DefaultRemoteDSN),
|
||||
|
||||
Reference in New Issue
Block a user