go.chromium.org/luci@v0.0.0-20240309015107-7cdc2e660f33/cv/internal/retention/common.go (about) 1 // Copyright 2024 The LUCI Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package retention 16 17 import ( 18 "errors" 19 "time" 20 ) 21 22 var retentionPeriod = 540 * 24 * time.Hour // ~= 1.5 years 23 // wipeoutTasksDistInterval defines the interval that wipeout tasks will be 24 // evenly distributed. 25 var wipeoutTasksDistInterval = 1 * time.Hour 26 27 // chunk splits []T into chunks of provided size. 28 // 29 // If the slice cannot be split evenly, the last chunk will contain all the 30 // remaining elements. The provided size must be larger than 0. 31 func chunk[T any](slice []T, size int) [][]T { 32 if size <= 0 { 33 panic(errors.New("size must be larger than 0")) 34 } 35 var chunks [][]T 36 for i := 0; i < len(slice); i += size { 37 end := min(i+size, len(slice)) 38 chunks = append(chunks, slice[i:end]) 39 } 40 return chunks 41 }