github.com/netdata/go.d.plugin@v0.58.1/agent/jobmgr/cache.go (about)

     1  // SPDX-License-Identifier: GPL-3.0-or-later
     2  
     3  package jobmgr
     4  
     5  import (
     6  	"context"
     7  
     8  	"github.com/netdata/go.d.plugin/agent/confgroup"
     9  )
    10  
    11  func newRunningJobsCache() *runningJobsCache {
    12  	return &runningJobsCache{}
    13  }
    14  
    15  func newRetryingJobsCache() *retryingJobsCache {
    16  	return &retryingJobsCache{}
    17  }
    18  
    19  type (
    20  	runningJobsCache  map[string]bool
    21  	retryingJobsCache map[uint64]retryTask
    22  
    23  	retryTask struct {
    24  		cancel  context.CancelFunc
    25  		timeout int
    26  		retries int
    27  	}
    28  )
    29  
    30  func (c runningJobsCache) put(cfg confgroup.Config) {
    31  	c[cfg.FullName()] = true
    32  }
    33  func (c runningJobsCache) remove(cfg confgroup.Config) {
    34  	delete(c, cfg.FullName())
    35  }
    36  func (c runningJobsCache) has(cfg confgroup.Config) bool {
    37  	return c[cfg.FullName()]
    38  }
    39  
    40  func (c retryingJobsCache) put(cfg confgroup.Config, retry retryTask) {
    41  	c[cfg.Hash()] = retry
    42  }
    43  func (c retryingJobsCache) remove(cfg confgroup.Config) {
    44  	delete(c, cfg.Hash())
    45  }
    46  func (c retryingJobsCache) lookup(cfg confgroup.Config) (retryTask, bool) {
    47  	v, ok := c[cfg.Hash()]
    48  	return v, ok
    49  }