MCPcopy Create free account
hub / github.com/openclaw/gogcli / Handle

Method Handle

internal/gmailwatch/processor.go:127–217  ·  view source on GitHub ↗
(ctx context.Context, notification Notification)

Source from the content-addressed store, hash-verified

125}
126
127func (p *Processor) Handle(ctx context.Context, notification Notification) (*Payload, error) {
128 if p.Repository == nil {
129 return nil, ErrMissingRepository
130 }
131
132 if notification.MessageID != "" {
133 state := p.Repository.Get()
134 if state.LastPushMessageID == notification.MessageID {
135 p.logf("watch: ignoring duplicate push %s", notification.MessageID)
136
137 return nil, ErrNoNewMessages
138 }
139 }
140
141 if err := p.checkRateLimitCircuit(p.currentTime()); err != nil {
142 return nil, err
143 }
144
145 startID, err := p.Repository.StartHistoryID(notification.HistoryID)
146 if err != nil {
147 return nil, err
148 }
149
150 if startID == 0 {
151 p.logStaleNotification(notification.HistoryID)
152
153 return nil, ErrNoNewMessages
154 }
155
156 if sleepErr := p.sleepForFetch(ctx); sleepErr != nil {
157 return nil, sleepErr
158 }
159
160 if p.NewSource == nil {
161 return nil, ErrMissingSourceFactory
162 }
163
164 source, err := p.NewSource(ctx)
165 if err != nil {
166 return nil, err
167 }
168
169 if source == nil {
170 return nil, ErrMissingSource
171 }
172
173 historyPage, err := source.ListHistory(ctx, startID, p.Config.HistoryMax, p.Config.HistoryTypes)
174 if err != nil {
175 if p.IsStaleHistoryError != nil && p.IsStaleHistoryError(err) {
176 return p.resync(ctx, source, notification)
177 }
178
179 return nil, p.openRateLimitCircuitIfNeeded(err)
180 }
181
182 nextHistoryID := notification.HistoryID
183 if historyPage.HistoryID != "" {
184 nextHistoryID = historyPage.HistoryID

Callers 12

ProcessMethod · 0.95
lockKeyringFileFunction · 0.80
unlockKeyringFileFunction · 0.80
handlePushMethod · 0.80
lockFileFunction · 0.80
unlockFileFunction · 0.80

Calls 13

logfMethod · 0.95
checkRateLimitCircuitMethod · 0.95
currentTimeMethod · 0.95
logStaleNotificationMethod · 0.95
sleepForFetchMethod · 0.95
ListHistoryMethod · 0.95
resyncMethod · 0.95
advanceHistoryMethod · 0.95
FetchMessagesMethod · 0.95
CollectHistoryMessageIDsFunction · 0.85
StartHistoryIDMethod · 0.80