MCPcopy Create free account
hub / github.com/cloudbase/garm / giteaUpdateLoop

Method giteaUpdateLoop

workers/cache/tool_cache.go:167–256  ·  view source on GitHub ↗

giteaUpdateLoop updates tools for gitea. The act runner can be downloaded without a token, unlike the github tools, which for GHES require a token.

()

Source from the content-addressed store, hash-verified

165// giteaUpdateLoop updates tools for gitea. The act runner can be downloaded
166// without a token, unlike the github tools, which for GHES require a token.
167func (t *toolsUpdater) giteaUpdateLoop() {
168 defer t.Stop()
169
170 // add some jitter
171 timerJitter, err := rand.Int(rand.Reader, big.NewInt(120))
172 if err != nil {
173 timerJitter = big.NewInt(0)
174 }
175 ticker := time.NewTicker(1*time.Minute + time.Duration(timerJitter.Int64())*time.Second)
176 defer ticker.Stop()
177
178 oldMetadataURL := ""
179 oldUseInternal := false
180reset:
181 metadataURL := appdefaults.GiteaRunnerReleasesURL
182 var useInternal bool
183 ep, ok := cache.GetEndpoint(t.entity.Credentials.Endpoint.Name)
184 if ok {
185 if ep.ToolsMetadataURL != "" {
186 metadataURL = ep.ToolsMetadataURL
187 }
188 if ep.UseInternalToolsMetadata != nil {
189 useInternal = *ep.UseInternalToolsMetadata
190 }
191 }
192
193 now := time.Now().UTC()
194 if now.After(t.lastUpdate.Add(time.Duration(giteaToolsUpdateDeadline)*time.Minute)) || oldMetadataURL != metadataURL || oldUseInternal != useInternal {
195 tools, err := getTools(t.ctx, metadataURL, useInternal)
196 if err != nil {
197 t.addStatusEvent(fmt.Sprintf("failed to update gitea tools: %q", err), params.EventError)
198 } else {
199 if useInternal {
200 t.addStatusEvent("using internal tools metadata", params.EventInfo)
201 } else {
202 t.addStatusEvent(fmt.Sprintf("successfully updated tools using metadata URL %s", metadataURL), params.EventInfo)
203 }
204 t.lastUpdate = now
205 oldMetadataURL = metadataURL
206 oldUseInternal = useInternal
207 cache.SetGithubToolsCache(t.entity, tools)
208 }
209 }
210
211 for {
212 t.mux.Lock()
213 if t.reset == nil {
214 t.reset = make(chan struct{})
215 }
216 t.mux.Unlock()
217 select {
218 case <-t.quit:
219 slog.DebugContext(t.ctx, "stopping tools updater")
220 return
221 case <-t.reset:
222 goto reset
223 case <-t.ctx.Done():
224 return

Callers 1

StartMethod · 0.95

Calls 11

StopMethod · 0.95
addStatusEventMethod · 0.95
GetEndpointFunction · 0.92
SetGithubToolsCacheFunction · 0.92
getToolsFunction · 0.85
AddMethod · 0.80
StopMethod · 0.65
LockMethod · 0.65
UnlockMethod · 0.65
DurationMethod · 0.45
DoneMethod · 0.45

Tested by

no test coverage detected