MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / refreshTutorialCatalog

Method refreshTutorialCatalog

internal/server/tutorials.go:173–194  ·  view source on GitHub ↗

refreshTutorialCatalog fetches the catalog and publishes the result, then closes done. It runs detached from any one request, so a client that goes away does not cancel the refresh everyone else is waiting on.

(done chan struct{})

Source from the content-addressed store, hash-verified

171// closes done. It runs detached from any one request, so a client that goes
172// away does not cancel the refresh everyone else is waiting on.
173func (s *Server) refreshTutorialCatalog(done chan struct{}) {
174 body, _, err := s.fetchTutorialBytes(context.Background(), tutorialsCatalogURL, tutorialsCatalogMaxSize)
175 var cat tutorialCatalog
176 if err == nil {
177 err = json.Unmarshal(body, &cat)
178 }
179 if err == nil && cat.Version != 1 {
180 err = fmt.Errorf("tutorials: catalog version %d is not 1", cat.Version)
181 }
182 c := &s.tutorials
183 c.mu.Lock()
184 if err != nil {
185 c.failedAt = time.Now()
186 } else {
187 c.catalog = &cat
188 c.fetchedAt = time.Now()
189 c.failedAt = time.Time{}
190 }
191 c.inflight = nil
192 c.mu.Unlock()
193 close(done)
194}
195
196func tutorialPosterPath(slug string) string {
197 return "/api/v1/tutorials/posters/" + slug

Callers 1

tutorialCatalogNowMethod · 0.95

Calls 5

fetchTutorialBytesMethod · 0.95
LockMethod · 0.80
UnlockMethod · 0.80
NowMethod · 0.65
closeFunction · 0.50

Tested by

no test coverage detected