Skip to content

Commit

Permalink
APIGOV-27875 - delay job pool checker and watcher until a job is regi…
Browse files Browse the repository at this point in the history
…stered
  • Loading branch information
vivekschauhan committed Jul 8, 2024
1 parent de615c6 commit af94c47
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions pkg/authz/oauth/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func NewProvider(idp corecfg.IDPConfig, tlsCfg corecfg.TLSConfig, proxyURL strin
metadata, err := p.fetchMetadata()
if err != nil {
p.logger.
WithField("name", p.cfg.GetIDPName()).
WithField("provider", p.cfg.GetIDPName()).
WithField("type", p.cfg.GetIDPType()).
WithField("metadata-url", p.metadataURL).
WithError(err).
Expand Down Expand Up @@ -371,6 +371,7 @@ func (p *provider) RegisterClient(clientReq ClientMetadata) (ClientMetadata, err
p.logger.
WithField("provider", p.cfg.GetIDPName()).
WithField("client-name", clientReq.GetClientName()).
WithField("client-id", clientReq.GetClientName()).
WithField("grant-type", clientReq.GetGrantTypes()).
WithField("token-auth-method", clientReq.GetTokenEndpointAuthMethod()).
WithField("response-type", clientReq.GetResponseTypes()).
Expand All @@ -381,6 +382,7 @@ func (p *provider) RegisterClient(clientReq ClientMetadata) (ClientMetadata, err

err = fmt.Errorf("error status code: %d, body: %s", response.Code, string(response.Body))
p.logger.
WithField("provider", p.cfg.GetIDPName()).
WithField("client-name", clientReq.GetClientName()).
WithField("grant-type", clientReq.GetGrantTypes()).
WithField("token-auth-method", clientReq.GetTokenEndpointAuthMethod()).
Expand Down Expand Up @@ -479,14 +481,14 @@ func (p *provider) UnregisterClient(clientID, accessToken string) error {
err := fmt.Errorf("error status code: %d, body: %s", response.Code, string(response.Body))
p.logger.
WithField("provider", p.cfg.GetIDPName()).
WithField("client-name", clientID).
WithField("client-id", clientID).
Error(err.Error())
return err
}

p.logger.
WithField("provider", p.cfg.GetIDPName()).
WithField("client-name", clientID).
WithField("client-id", clientID).
Info("unregistered client")
return nil
}
Expand Down
12 changes: 7 additions & 5 deletions pkg/jobs/pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,6 @@ func newPool() *Pool {
}
newPool.SetStatus(PoolStatusInitializing)

// start routine to check all job status funcs and catch any failures
go newPool.jobChecker()
// start the pool watcher
go newPool.watchJobs()

return &newPool
}

Expand All @@ -75,6 +70,13 @@ func (p *Pool) setBackoff(backoff *backoff) {
func (p *Pool) recordJob(job JobExecution) string {
p.jobsMapLock.Lock()
defer p.jobsMapLock.Unlock()
if len(p.jobs) > 0 && p.poolStatus == PoolStatusInitializing {

This comment has been minimized.

Copy link
@jcollins-axway

jcollins-axway Jul 8, 2024

Collaborator

Should this check be len(p.jobs) == 0 && p.poolStatus == PoolStatusInitializing ? To only start them when initializing and no jobs yet registered?

This comment has been minimized.

Copy link
@vivekschauhan

vivekschauhan Jul 9, 2024

Author Collaborator

You're right. Used. p.GetStatus() to avoid data race on poolStatus

// start routine to check all job status funcs and catch any failures
go p.jobChecker()
// start the pool watcher
go p.watchJobs()
}

p.logger.
WithField("job-id", job.GetID()).
WithField("job-name", job.GetName()).
Expand Down

0 comments on commit af94c47

Please sign in to comment.