You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: compensator.go
    path of file: ./repos/erda/internal/tools/pipeline/providers/resourcegc
    
    the code of the file until where you have to start completion: // Copyright (c) 2021 Terminus, Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      http://www.apache.
    
func (r *provider) getNeedGCPipelines(pageNum int, isSnippet bool) ([]spec.Pipeline, int, error) {
	var pipelineResults []spec.Pipeline

	var req pb.PipelinePagingRequest
	req.PageNum = int64(pageNum)
	req.PageSize = 100
	req.LargePageSize = true
	req.AscCols = []string{"id"}
	for _, end := range apistructs.PipelineEndStatuses {
		req.Status = append(req.Status, end.String())
	}
	req.AllSources = true
	req.IncludeSnippet = isSnippet
	result, err := r.dbClient.PageListPipelines(&req)
	if err != nil {
		return nil, 0, fmt.Errorf("failed to compensate pipeline req %v err: %v", req, err)
	}

	pipelines := result.Pipelines
	for _, p := range pipelines {
		if !p.Status.IsEndStatus() {
			continue
		}

		if p.Extra.CompleteReconcilerGC {
			continue
		}

		// if not found gc key in etcd, meaning wait-gc failed when tear down pipeline
		// should add CompleteReconcilerGC-false and not-found-gc-key pipeline to need gc pipelines
		notFound, err := r.js.Notfound(context.Background(), makePipelineGCKey(p.Extra.Namespace))
		if err != nil {
			r.Log.Errorf("get is-existed gc key failed, namespace: %s, cause pipelineID: %d(continue), err: %v", p.Extra.Namespace,
				p.ID, err)
			continue
		}
		if !notFound {
			continue
		}

		ttl := p.GetResourceGCTTL()
		if ttl <= 0 {
			ttl = defaultGCTime
		}

		var endTime = p.TimeEnd
		if endTime == nil {
			endTime = p.TimeUpdated
		}

		if endTime == nil || endTime.IsZero() {
			continue
		}

		if uint64(time.Now().Unix()-endTime.Unix()) < (ttl + bufferTime) {
			continue
		}

		pipelineResults = append(pipelineResults, p)
	}

	return pipelineResults, len(pipelines), nil
}