MCPcopy Create free account
hub / github.com/baidu/EasyFaaS / prepareUserCode

Method prepareUserCode

pkg/funclet/warmup.go:181–228  ·  view source on GitHub ↗
(ctx *funcletCtx.Context, code *api.CodeStorage, codeSha256, hexCodeSha256 string)

Source from the content-addressed store, hash-verified

179}
180
181func (f *Funclet) prepareUserCode(ctx *funcletCtx.Context, code *api.CodeStorage, codeSha256, hexCodeSha256 string) (string, error) {
182 destination := f.GetUserCodePath(hexCodeSha256)
183 codeFolder := f.Options.CachePath
184 defer ctx.Logger.TimeTrack(time.Now(), "Prepare user code",
185 zap.String("codesha256", codeSha256),
186 zap.String("hexcode", hexCodeSha256),
187 zap.String("repositoryType", "bos"),
188 )
189
190 // serial fetch code
191 prepareCodeChain, isMaster := f.HandlingChanMap.GetChan(hexCodeSha256)
192 if !isMaster {
193 <-prepareCodeChain
194 } else {
195 defer f.HandlingChanMap.CloseChan(hexCodeSha256)
196 }
197
198 // check code
199 foundCode := f.CodeManager.FindCode(codeFolder, hexCodeSha256)
200 foundCodeCompleteTag := f.CodeManager.FindCodeCompeleteTag(codeFolder, hexCodeSha256)
201 if foundCode && foundCodeCompleteTag {
202 ctx.Logger.V(6).Infof("Code cache %s found", destination)
203 return destination, nil
204 }
205
206 zipFilePath, err := f.CodeManager.FetchCode(ctx, code)
207 if err != nil {
208 return "", err
209 }
210 defer os.Remove(zipFilePath)
211
212 // check CodeSha256
213 if !f.CodeManager.CheckCode(ctx, zipFilePath, codeSha256) {
214 ctx.Logger.Warnf("Code %s checksum failed", zipFilePath)
215 return "", errors.New("CodeSha256 checksum failed")
216 }
217
218 // unzip code
219 if err := f.CodeManager.UnzipCode(ctx, zipFilePath, destination); err != nil {
220 return "", err
221 }
222
223 // mark as finished
224 if err := f.CodeManager.CreateCodeCompeleteTag(codeFolder, hexCodeSha256); err != nil {
225 return "", err
226 }
227 return destination, nil
228}
229
230func (f *Funclet) prepareRuntimeConf(ctx *funcletCtx.Context, warmUpContainerArgs *api.WarmUpContainerArgs) (string, error) {
231 confPath := f.GetContainerConfPath(ctx.Container.Hostname)

Callers 2

WarmUpMethod · 0.95
IDEWarmUpMethod · 0.95

Calls 15

GetUserCodePathMethod · 0.95
TimeTrackMethod · 0.80
GetChanMethod · 0.80
CloseChanMethod · 0.80
InfofMethod · 0.80
VMethod · 0.80
WarnfMethod · 0.80
NewMethod · 0.80
StringMethod · 0.65
FindCodeMethod · 0.65
FindCodeCompeleteTagMethod · 0.65
FetchCodeMethod · 0.65

Tested by

no test coverage detected