diff options
Diffstat (limited to 'src/go/collectors/go.d.plugin/agent/jobmgr/cache.go')
-rw-r--r-- | src/go/collectors/go.d.plugin/agent/jobmgr/cache.go | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/agent/jobmgr/cache.go b/src/go/collectors/go.d.plugin/agent/jobmgr/cache.go new file mode 100644 index 0000000000..53a1f73253 --- /dev/null +++ b/src/go/collectors/go.d.plugin/agent/jobmgr/cache.go @@ -0,0 +1,49 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package jobmgr + +import ( + "context" + + "github.com/netdata/go.d.plugin/agent/confgroup" +) + +func newRunningJobsCache() *runningJobsCache { + return &runningJobsCache{} +} + +func newRetryingJobsCache() *retryingJobsCache { + return &retryingJobsCache{} +} + +type ( + runningJobsCache map[string]bool + retryingJobsCache map[uint64]retryTask + + retryTask struct { + cancel context.CancelFunc + timeout int + retries int + } +) + +func (c runningJobsCache) put(cfg confgroup.Config) { + c[cfg.FullName()] = true +} +func (c runningJobsCache) remove(cfg confgroup.Config) { + delete(c, cfg.FullName()) +} +func (c runningJobsCache) has(cfg confgroup.Config) bool { + return c[cfg.FullName()] +} + +func (c retryingJobsCache) put(cfg confgroup.Config, retry retryTask) { + c[cfg.Hash()] = retry +} +func (c retryingJobsCache) remove(cfg confgroup.Config) { + delete(c, cfg.Hash()) +} +func (c retryingJobsCache) lookup(cfg confgroup.Config) (retryTask, bool) { + v, ok := c[cfg.Hash()] + return v, ok +} |