From bdb84a3055d272acbff7066668901c7c1cf970f0 Mon Sep 17 00:00:00 2001 From: Jason Collins Date: Thu, 20 Oct 2022 14:59:32 -0700 Subject: [PATCH] APIGOV-23935 - fix merge issues --- discovery/pkg/apigee/pollproductsjob.go | 23 +++++++++++++++++++++++ discovery/pkg/apigee/pollspecsjob.go | 6 ++++++ 2 files changed, 29 insertions(+) diff --git a/discovery/pkg/apigee/pollproductsjob.go b/discovery/pkg/apigee/pollproductsjob.go index d0c1fb5..ba339b5 100644 --- a/discovery/pkg/apigee/pollproductsjob.go +++ b/discovery/pkg/apigee/pollproductsjob.go @@ -44,6 +44,8 @@ type pollProductsJob struct { publishFunc agent.PublishAPIFunc logger log.FieldLogger workers int + running bool + runningLock sync.Mutex } func newPollProductsJob(client productClient, cache productCache, specsReady jobFirstRunDone, workers int) *pollProductsJob { @@ -55,6 +57,7 @@ func newPollProductsJob(client productClient, cache productCache, specsReady job logger: log.NewFieldLogger().WithComponent("pollProducts").WithPackage("apigee"), publishFunc: agent.PublishAPI, workers: workers, + runningLock: sync.Mutex{}, } return job } @@ -73,8 +76,28 @@ func (j *pollProductsJob) Status() error { return nil } +func (j *pollProductsJob) updateRunning(running bool) { + j.runningLock.Lock() + defer j.runningLock.Unlock() + j.running = running +} + +func (j *pollProductsJob) isRunning() bool { + j.runningLock.Lock() + defer j.runningLock.Unlock() + return j.running +} + func (j *pollProductsJob) Execute() error { j.logger.Trace("executing") + + if j.isRunning() { + j.logger.Warn("previous spec poll job run has not completed, will run again on next interval") + return nil + } + j.updateRunning(true) + defer j.updateRunning(false) + products, err := j.client.GetProducts() if err != nil { j.logger.WithError(err).Error("getting products") diff --git a/discovery/pkg/apigee/pollspecsjob.go b/discovery/pkg/apigee/pollspecsjob.go index 85a9ce6..db1c461 100644 --- a/discovery/pkg/apigee/pollspecsjob.go +++ b/discovery/pkg/apigee/pollspecsjob.go @@ -57,6 +57,12 @@ func (j *pollSpecsJob) Status() error { return nil } +func (j *pollSpecsJob) updateRunning(running bool) { + j.runningLock.Lock() + defer j.runningLock.Unlock() + j.running = running +} + func (j *pollSpecsJob) isRunning() bool { j.runningLock.Lock() defer j.runningLock.Unlock()