LastImportTime for resource. (#112153)
* LastImportTime for resource. * Make StorageBackendImpl implement GetResourceLastImportTimes * More missing implementations of GetResourceLastImportTimes * Fix import. * Skip TestGetResourceLastImportTime in TestBadgerKVStorageBackend. * Implement GetResourceLastImportTimes by mockStorageBackend * Bump test tolerance. * Fix postgres query and timezone. * Fix postgres query and timezone. * Make linter happy.
This commit is contained in:
@@ -955,3 +955,51 @@ func (b *backend) fetchLatestHistoryRV(ctx context.Context, x db.ContextExecer,
|
||||
}
|
||||
return res.ResourceVersion, nil
|
||||
}
|
||||
|
||||
func (b *backend) GetResourceLastImportTimes(ctx context.Context) iter.Seq2[resource.ResourceLastImportTime, error] {
|
||||
ctx, span := b.tracer.Start(ctx, tracePrefix+"GetLastImportTimes")
|
||||
defer span.End()
|
||||
|
||||
rows, err := dbutil.QueryRows(ctx, b.db, sqlResourceLastImportTimeQuery, &sqlResourceLastImportTimeQueryRequest{SQLTemplate: sqltemplate.New(b.dialect)})
|
||||
if err != nil {
|
||||
return func(yield func(resource.ResourceLastImportTime, error) bool) {
|
||||
yield(resource.ResourceLastImportTime{}, err)
|
||||
}
|
||||
}
|
||||
|
||||
return func(yield func(resource.ResourceLastImportTime, error) bool) {
|
||||
closeOnDefer := true
|
||||
defer func() {
|
||||
if closeOnDefer {
|
||||
_ = rows.Close() // Close while ignoring errors.
|
||||
}
|
||||
}()
|
||||
|
||||
for rows.Next() {
|
||||
// If context has finished, return early.
|
||||
if ctx.Err() != nil {
|
||||
yield(resource.ResourceLastImportTime{}, ctx.Err())
|
||||
return
|
||||
}
|
||||
|
||||
row := resource.ResourceLastImportTime{}
|
||||
err = rows.Scan(&row.Namespace, &row.Group, &row.Resource, &row.LastImportTime)
|
||||
if err != nil {
|
||||
yield(resource.ResourceLastImportTime{}, err)
|
||||
return
|
||||
}
|
||||
|
||||
if !yield(row, nil) {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
closeOnDefer = false
|
||||
|
||||
// Close and report error, if any.
|
||||
err := rows.Close()
|
||||
if err != nil {
|
||||
yield(resource.ResourceLastImportTime{}, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user