Skip to content

Commit

Permalink
APIGOV-23935 - fix merge issues
Browse files Browse the repository at this point in the history
  • Loading branch information
jcollins-axway committed Oct 20, 2022
1 parent 668abfb commit bdb84a3
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 0 deletions.
23 changes: 23 additions & 0 deletions discovery/pkg/apigee/pollproductsjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions discovery/pkg/apigee/pollspecsjob.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bdb84a3

Please sign in to comment.