MCPcopy Create free account
hub / github.com/cloudwan/gohan / Run

Method Run

server/sync_writer.go:68–112  ·  view source on GitHub ↗

Run starts a loop to keep running Sync(). This method blocks until the ctx is canceled.

(ctx context.Context)

Source from the content-addressed store, hash-verified

66// Run starts a loop to keep running Sync().
67// This method blocks until the ctx is canceled.
68func (writer *SyncWriter) Run(ctx context.Context) error {
69 pollingTicker := time.Tick(eventPollingTime)
70 committed := transactionCommitInformer()
71
72 recentlySynced := false
73 for {
74 err := func() error {
75 lost, err := writer.sync.Lock(syncPath, true)
76 if err != nil {
77 return err
78 }
79 defer writer.sync.Unlock(syncPath)
80
81 for {
82 select {
83 case <-lost:
84 return fmt.Errorf("lost lock for sync")
85 case <-ctx.Done():
86 return nil
87 case <-pollingTicker:
88 if recentlySynced {
89 recentlySynced = false
90 continue
91 }
92 case <-committed:
93 recentlySynced = true
94 }
95 _, err := writer.Sync()
96 if err != nil {
97 return err
98 }
99 }
100 }()
101
102 if err != nil {
103 log.Error("sync writer is intrupted: %s", err)
104 }
105
106 select {
107 case <-ctx.Done():
108 return ctx.Err()
109 case <-time.After(writer.backoff):
110 }
111 }
112}
113
114// Sync runs a synchronization iteration, which
115// executes requests in the event table.

Callers 2

RunServerFunction · 0.95

Calls 6

SyncMethod · 0.95
LockMethod · 0.65
UnlockMethod · 0.65
ErrorfMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected