Skip to content

Commit

Permalink
Do not re-use connections
Browse files Browse the repository at this point in the history
Processor Edition

In order to avoid stale connections to Salesforce and files.com, do not
re-use those connections (the clients) and rather create new client
connections when needed.

Issue: #177
Signed-off-by: Nicolas Bock <[email protected]>
  • Loading branch information
nicolasbock committed Sep 13, 2024
1 parent 0fa3247 commit b7287c5
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
5 changes: 4 additions & 1 deletion cmd/processor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,10 @@ func main() {
panic(err)
}

p, err := processor.NewProcessor(filesClient, sfClient, natsClient, cfg, nil)
salesforceClientFactory := &common.BaseSalesforceClientFactory{}
filesComClientFactory := &common.BaseFilesComClientFactory{}

p, err := processor.NewProcessor(filesClient, sfClient, filesComClientFactory, salesforceClientFactory, natsClient, cfg, nil)
if err != nil {
panic(err)
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (runner *ReportRunner) UploadAndSaveReport(report *ReportToExecute, caseNum
log.Debugf("Fetching files for path '%s' from db", filePath)
result := runner.Db.Where("path = ?", filePath).First(&file)
if result.Error != nil {
return fmt.Errorf("File not found with path '%s' in database", filePath)
return fmt.Errorf("file not found with path '%s' in database", filePath)
}

log.Infof("Fetching case with number '%s' from Salesforce", caseNumber)
Expand Down Expand Up @@ -363,7 +363,8 @@ func NewBaseSubscriber(filesClient common.FilesComClient, salesforceClient commo
AutoAck: false,
JSON: true,
Deadline: defaultHandlerDeadline,
}, Reports: reports,
},
Reports: reports,
}

subscriber.FilesComClient = filesClient
Expand All @@ -376,6 +377,7 @@ func NewBaseSubscriber(filesClient common.FilesComClient, salesforceClient commo
}

func NewProcessor(filesClient common.FilesComClient, salesforceClient common.SalesforceClient,
filesComClientFactory common.FilesComClientFactory, salesforceClientFactory common.SalesforceClientFactory,
provider pubsub.Provider, cfg *config.Config, dbConn *gorm.DB) (*Processor, error) {
var err error
if dbConn == nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/processor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func (s *ProcessorTestSuite) TestRunProcessor() {
salesforceClient := test.SalesforceClient{}

provider := &memory.MemoryProvider{}
processor, _ := NewProcessor(&filesComClient, &salesforceClient, provider, s.config, s.db)
processor, _ := NewProcessor(&filesComClient, &salesforceClient, &test.FilesComClientFactory{}, &test.SalesforceClientFactory{}, provider, s.config, s.db)

ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
defer cancel()
Expand Down

0 comments on commit b7287c5

Please sign in to comment.