tangled
alpha
login
or
join now
atscan.net
/
plcbundle-go
1
fork
atom
[DEPRECATED] Go implementation of plcbundle
1
fork
atom
overview
issues
pulls
pipelines
fix server sync
tree.fail
4 months ago
aa2909ec
37462ae5
+7
-42
2 changed files
expand all
collapse all
unified
split
bundle
manager.go
internal
sync
syncer.go
+4
-33
bundle/manager.go
···
1378
1378
1379
1379
// RunSyncLoop runs continuous sync loop (delegates to internal/sync)
1380
1380
func (m *Manager) RunSyncLoop(ctx context.Context, config *internalsync.SyncLoopConfig) error {
1381
1381
-
adapter := &syncManagerAdapter{mgr: m}
1382
1382
-
return internalsync.RunSyncLoop(ctx, adapter, config)
1381
1381
+
// Manager itself implements the SyncManager interface
1382
1382
+
return internalsync.RunSyncLoop(ctx, m, config)
1383
1383
}
1384
1384
1385
1385
// RunSyncOnce performs a single sync cycle
1386
1386
func (m *Manager) RunSyncOnce(ctx context.Context, config *internalsync.SyncLoopConfig, verbose bool) (int, error) {
1387
1387
-
adapter := &syncManagerAdapter{mgr: m}
1388
1388
-
return internalsync.SyncOnce(ctx, adapter, config, verbose)
1387
1387
+
// Manager itself implements the SyncManager interface
1388
1388
+
return internalsync.SyncOnce(ctx, m, config, verbose)
1389
1389
}
1390
1390
-
1391
1391
-
// syncManagerAdapter adapts Manager to sync.SyncManager interface
1392
1392
-
type syncManagerAdapter struct {
1393
1393
-
mgr *Manager
1394
1394
-
}
1395
1395
-
1396
1396
-
func (a *syncManagerAdapter) GetLastBundleNumber() int {
1397
1397
-
return a.mgr.GetLastBundleNumber()
1398
1398
-
}
1399
1399
-
1400
1400
-
func (a *syncManagerAdapter) GetMempoolCount() int {
1401
1401
-
return a.mgr.GetMempoolCount()
1402
1402
-
}
1403
1403
-
1404
1404
-
func (a *syncManagerAdapter) FetchNextBundle(ctx context.Context, quiet bool) (int, error) {
1405
1405
-
bundleNum, _, err := a.mgr.FetchAndSaveNextBundle(ctx, quiet)
1406
1406
-
return bundleNum, err
1407
1407
-
}
1408
1408
-
1409
1409
-
func (a *syncManagerAdapter) SaveBundle(ctx context.Context, bundleNum int, quiet bool) (time.Duration, error) {
1410
1410
-
// Already saved in FetchAndSaveNextBundle
1411
1411
-
return 0, nil
1412
1412
-
}
1413
1413
-
1414
1414
-
func (a *syncManagerAdapter) SaveMempool() error {
1415
1415
-
return a.mgr.SaveMempool()
1416
1416
-
}
1417
1417
-
1418
1418
-
// bundle/manager.go
1419
1390
1420
1391
// EnsureDIDIndex ensures DID index is built and up-to-date
1421
1392
// Returns true if index was built/rebuilt, false if already up-to-date
+3
-9
internal/sync/syncer.go
···
31
31
type SyncManager interface {
32
32
GetLastBundleNumber() int
33
33
GetMempoolCount() int
34
34
-
FetchNextBundle(ctx context.Context, quiet bool) (int, error) // returns bundle number
35
35
-
SaveBundle(ctx context.Context, bundleNum int, quiet bool) (time.Duration, error)
34
34
+
// Returns: bundleNumber, indexUpdateTime, error
35
35
+
FetchAndSaveNextBundle(ctx context.Context, quiet bool) (int, time.Duration, error)
36
36
SaveMempool() error
37
37
}
38
38
···
116
116
// Keep fetching until caught up
117
117
for {
118
118
// quiet = !verbose
119
119
-
bundleNum, err := mgr.FetchNextBundle(ctx, !verbose)
119
119
+
bundleNum, indexTime, err := mgr.FetchAndSaveNextBundle(ctx, !verbose)
120
120
if err != nil {
121
121
if isEndOfDataError(err) {
122
122
break
123
123
}
124
124
return fetchedCount, fmt.Errorf("fetch failed: %w", err)
125
125
-
}
126
126
-
127
127
-
// Save bundle and track index update time
128
128
-
indexTime, err := mgr.SaveBundle(ctx, bundleNum, !verbose)
129
129
-
if err != nil {
130
130
-
return fetchedCount, fmt.Errorf("save failed: %w", err)
131
125
}
132
126
133
127
fetchedCount++