How to use batchProcessBuilds method of main Package

Best Syzkaller code snippet using main.batchProcessBuilds

asset_storage.go

Source:asset_storage.go Github

copy

Full Screen

...96 ns: ns,97 c: c,98 }99 const buildBatchSize = 16100 err := ad.batchProcessBuilds(buildBatchSize)101 if err != nil {102 return fmt.Errorf("build batch processing failed: %w", err)103 }104 return nil105}106type assetDeprecator struct {107 ns string108 c context.Context109 bugsQueried bool110 relevantBugs map[string]bool111}112const keepAssetsForClosedBugs = time.Hour * 24 * 30113func (ad *assetDeprecator) queryBugs() error {114 if ad.bugsQueried {115 return nil116 }117 var openBugKeys []*db.Key118 var closedBugKeys []*db.Key119 g, _ := errgroup.WithContext(context.Background())120 g.Go(func() error {121 // Query open bugs.122 var err error123 openBugKeys, err = db.NewQuery("Bug").124 Filter("Namespace=", ad.ns).125 Filter("Status=", BugStatusOpen).126 KeysOnly().127 GetAll(ad.c, nil)128 if err != nil {129 return fmt.Errorf("failed to fetch open builds: %w", err)130 }131 return nil132 })133 g.Go(func() error {134 // Query recently closed bugs.135 var err error136 closedBugKeys, err = db.NewQuery("Bug").137 Filter("Namespace=", ad.ns).138 Filter("Closed>", timeNow(ad.c).Add(-keepAssetsForClosedBugs)).139 KeysOnly().140 GetAll(ad.c, nil)141 if err != nil {142 return fmt.Errorf("failed to fetch closed builds: %w", err)143 }144 return nil145 })146 err := g.Wait()147 if err != nil {148 return fmt.Errorf("failed to query bugs: %w", err)149 }150 ad.relevantBugs = map[string]bool{}151 for _, key := range append(append([]*db.Key{}, openBugKeys...), closedBugKeys...) {152 ad.relevantBugs[key.String()] = true153 }154 return nil155}156func (ad *assetDeprecator) buildArchivePolicy(build *Build, asset *Asset) (bool, error) {157 // If the asset is reasonably new, we always keep it.158 const alwaysKeepPeriod = time.Hour * 24 * 14159 if asset.CreateDate.After(timeNow(ad.c).Add(-alwaysKeepPeriod)) {160 return true, nil161 }162 // Query builds to see whether there's a newer same-type asset on the same week.163 var builds []*Build164 _, err := db.NewQuery("Build").165 Filter("Namespace=", ad.ns).166 Filter("Manager=", build.Manager).167 Filter("Assets.Type=", asset.Type).168 Filter("Assets.CreateDate>", asset.CreateDate).169 Limit(1).170 Order("Assets.CreateDate").171 GetAll(ad.c, &builds)172 if err != nil {173 return false, fmt.Errorf("failed to query newer assets: %w", err)174 }175 log.Infof(ad.c, "running archive policy for %s, date %s; queried %d builds",176 asset.DownloadURL, asset.CreateDate, len(builds))177 sameWeek := false178 if len(builds) > 0 {179 origY, origW := asset.CreateDate.ISOWeek()180 for _, nextAsset := range builds[0].Assets {181 if nextAsset.Type != asset.Type {182 continue183 }184 if nextAsset.CreateDate.Before(asset.CreateDate) ||185 nextAsset.CreateDate.Equal(asset.CreateDate) {186 continue187 }188 nextY, nextW := nextAsset.CreateDate.ISOWeek()189 if origY == nextY && origW == nextW {190 log.Infof(ad.c, "found a newer asset: %s, date %s",191 nextAsset.DownloadURL, nextAsset.CreateDate)192 sameWeek = true193 break194 }195 }196 }197 return !sameWeek, nil198}199func (ad *assetDeprecator) buildBugStatusPolicy(build *Build) (bool, error) {200 if err := ad.queryBugs(); err != nil {201 return false, fmt.Errorf("failed to query bugs: %w", err)202 }203 keys, err := db.NewQuery("Crash").204 Filter("BuildID=", build.ID).205 KeysOnly().206 GetAll(ad.c, nil)207 if err != nil {208 return false, fmt.Errorf("failed to query crashes: %w", err)209 }210 for _, key := range keys {211 bugKey := key.Parent()212 if _, ok := ad.relevantBugs[bugKey.String()]; ok {213 // At least one crash is related to an opened/recently closed bug.214 return true, nil215 }216 }217 return false, nil218}219func (ad *assetDeprecator) needThisBuildAsset(build *Build, buildAsset *Asset) (bool, error) {220 if buildAsset.Type == dashapi.HTMLCoverageReport {221 // We want to keep coverage reports forever, not just222 // while there are any open bugs. But we don't want to223 // keep all coverage reports, just a share of them.224 return ad.buildArchivePolicy(build, buildAsset)225 }226 if build.Type == BuildNormal || build.Type == BuildFailed {227 // A build-related asset, keep it only while there are open bugs with crashes228 // related to this build.229 return ad.buildBugStatusPolicy(build)230 }231 // TODO: fix this once this is no longer the case.232 return false, fmt.Errorf("job-related assets are not supported yet")233}234func (ad *assetDeprecator) updateBuild(buildID string, urlsToDelete []string) error {235 toDelete := map[string]bool{}236 for _, url := range urlsToDelete {237 toDelete[url] = true238 }239 tx := func(c context.Context) error {240 build, err := loadBuild(ad.c, ad.ns, buildID)241 if build == nil || err != nil {242 // Assume the DB has been updated in the meanwhile.243 return nil244 }245 newAssets := []Asset{}246 for _, asset := range build.Assets {247 if _, ok := toDelete[asset.DownloadURL]; !ok {248 newAssets = append(newAssets, asset)249 }250 }251 build.Assets = newAssets252 build.AssetsLastCheck = timeNow(ad.c)253 if _, err := db.Put(ad.c, buildKey(ad.c, ad.ns, buildID), build); err != nil {254 return fmt.Errorf("failed to save build: %w", err)255 }256 return nil257 }258 if err := db.RunInTransaction(ad.c, tx, nil); err != nil {259 return fmt.Errorf("failed to update build: %w", err)260 }261 return nil262}263func (ad *assetDeprecator) batchProcessBuilds(count int) error {264 // We cannot query only the Build with non-empty Assets array and yet sort265 // by AssetsLastCheck. The datastore returns "The first sort property must266 // be the same as the property to which the inequality filter is applied.267 // In your query the first sort property is AssetsLastCheck but the inequality268 // filter is on Assets.DownloadURL.269 // So we have to omit Filter("Assets.DownloadURL>", ""). here.270 var builds []*Build271 _, err := db.NewQuery("Build").272 Filter("Namespace=", ad.ns).273 Order("AssetsLastCheck").274 Limit(count).275 GetAll(ad.c, &builds)276 if err != nil {277 return fmt.Errorf("failed to fetch builds: %w", err)...

Full Screen

Full Screen

batchProcessBuilds

Using AI Code Generation

copy

Full Screen

1import (2func main() {3 runtime.GOMAXPROCS(runtime.NumCPU())4 fmt.Println("Number of CPU's: ", runtime.NumCPU())5 start := time.Now()6 batchProcessBuilds()7 elapsed := time.Since(start)8 fmt.Println("Time taken: ", elapsed)9}10import (11func batchProcessBuilds() {12 file, err := os.Open("input.txt")13 if err != nil {14 fmt.Println("Error in opening file")15 }16 defer file.Close()17 reader := bufio.NewReader(file)18 line, _, err := reader.ReadLine()19 for err == nil {20 lineString := string(line)21 lineStringArray := strings.Split(lineString, " ")22 noOfBuilds, _ := strconv.Atoi(lineStringArray[0])23 noOfDays, _ := strconv.Atoi(lineStringArray[1])24 noOfDaysToBuild, _ := strconv.Atoi(lineStringArray[2])25 noOfDaysToTest, _ := strconv.Atoi(lineStringArray[3])26 noOfDaysToDeploy, _ := strconv.Atoi(lineStringArray[4])27 noOfDaysToRepair, _ := strconv.Atoi(lineStringArray[5])28 noOfDaysToFix, _ := strconv.Atoi(lineStringArray[6])29 noOfDaysToTestAgain, _ := strconv.Atoi(lineStringArray[7])30 noOfDaysToDeployAgain, _ := strconv.Atoi(lineStringArray[8])31 noOfDaysToRepairAgain, _ := strconv.Atoi(lineStringArray[9])32 noOfDaysToFixAgain, _ := strconv.Atoi(lineStringArray[10])33 noOfDaysToTestAgainAgain, _ := strconv.Atoi(lineStringArray[11])34 noOfDaysToDeployAgainAgain, _ := strconv.Atoi(lineStringArray[12])35 noOfDaysToRepairAgainAgain, _ := strconv.Atoi(lineStringArray[13])36 noOfDaysToFixAgainAgain, _ := strconv.Atoi(lineStringArray[14])37 noOfDaysToTestAgainAgainAgain, _ := strconv.Atoi(lineStringArray[15])

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Syzkaller automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used method in

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful