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{})
| 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. |
| 173 | func (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 | |
| 196 | func tutorialPosterPath(slug string) string { |
| 197 | return "/api/v1/tutorials/posters/" + slug |
no test coverage detected