Skip to content

Commit

Permalink
fixup! Do not re-use connections
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasbock committed Sep 13, 2024
1 parent b7287c5 commit 22eba52
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 16 deletions.
5 changes: 4 additions & 1 deletion cmd/processor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ func main() {

ctx, cancel := context.WithCancel(context.Background())

if err := p.Run(ctx, func(fc common.FilesComClient, sf common.SalesforceClient, name, topic string,
if err := p.Run(ctx, func(fc common.FilesComClient, sf common.SalesforceClient,
filesComClientFactory common.FilesComClientFactory,
salesforceClientFactory common.SalesforceClientFactory,
name, topic string,
reports map[string]config.Report, cfg *config.Config, dbConn *gorm.DB) pubsub.Subscriber {
log.Infof("Subscribing: %s - to topic: %s", name, topic)
return processor.NewBaseSubscriber(fc, sf, name, topic, reports, cfg, dbConn)
Expand Down
39 changes: 24 additions & 15 deletions pkg/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,14 @@ import (
)

type Processor struct {
Config *config.Config
Db *gorm.DB
FilesClient common.FilesComClient
Hostname string
Provider pubsub.Provider
SalesforceClient common.SalesforceClient
Config *config.Config
Db *gorm.DB
FilesClient common.FilesComClient
FilesComClientFactory common.FilesComClientFactory
Hostname string
Provider pubsub.Provider
SalesforceClient common.SalesforceClient
SalesforceClientFactory common.SalesforceClientFactory
}

type BaseSubscriber struct {
Expand Down Expand Up @@ -162,7 +164,7 @@ func (runner *ReportRunner) UploadAndSaveReport(report *ReportToExecute, caseNum
log.Debugf("Uploading script output %s", dst_fname)
uploadedFilePath, err := runner.FilescomClient.Upload(string(output), dst_fname)
if err != nil {
return fmt.Errorf("Failed to upload file '%s': %s", dst_fname, err.Error())
return fmt.Errorf("failed to upload file '%s': %s", dst_fname, err.Error())
}

log.Debugf("Successfully uploaded file '%s'", uploadedFilePath.Path)
Expand Down Expand Up @@ -393,12 +395,14 @@ func NewProcessor(filesClient common.FilesComClient, salesforceClient common.Sal
}

return &Processor{
Config: cfg,
Db: dbConn,
FilesClient: filesClient,
Hostname: hostname,
Provider: provider,
SalesforceClient: salesforceClient,
Config: cfg,
Db: dbConn,
FilesClient: filesClient,
FilesComClientFactory: filesComClientFactory,
Hostname: hostname,
Provider: provider,
SalesforceClient: salesforceClient,
SalesforceClientFactory: salesforceClientFactory,
}, nil
}

Expand Down Expand Up @@ -541,7 +545,11 @@ func (p *Processor) BatchSalesforceComments(ctx *context.Context, interval time.
}

func (p *Processor) Run(ctx context.Context, newSubscriberFn func(filesClient common.FilesComClient,
salesforceClient common.SalesforceClient, name, topic string, reports map[string]config.Report, cfg *config.Config, dbConn *gorm.DB) pubsub.Subscriber) error {
salesforceClient common.SalesforceClient,
filesComClientFactory common.FilesComClientFactory,
salesforceClientFactory common.SalesforceClientFactory,
name, topic string, reports map[string]config.Report,
cfg *config.Config, dbConn *gorm.DB) pubsub.Subscriber) error {

if ctx == nil {
var cancel context.CancelFunc
Expand All @@ -556,7 +564,8 @@ func (p *Processor) Run(ctx context.Context, newSubscriberFn func(filesClient co
})

for event := range p.Config.Processor.SubscribeTo {
go pubsub.Subscribe(newSubscriberFn(p.FilesClient, p.SalesforceClient, p.Hostname, event, p.getReportsByTopic(event), p.Config, p.Db))
go pubsub.Subscribe(newSubscriberFn(p.FilesClient, p.SalesforceClient, p.FilesComClientFactory, p.SalesforceClientFactory,
p.Hostname, event, p.getReportsByTopic(event), p.Config, p.Db))
}

interval, err := time.ParseDuration(p.Config.Processor.BatchCommentsEvery)
Expand Down
2 changes: 2 additions & 0 deletions pkg/processor/processor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ func (s *ProcessorTestSuite) TestRunProcessor() {
var called = 0

_ = processor.Run(ctx, func(fc common.FilesComClient, sf common.SalesforceClient,
filesComClientFactory common.FilesComClientFactory,
salesforceClientFactory common.SalesforceClientFactory,
name string, topic string, reports map[string]config.Report, cfg *config.Config, dbConn *gorm.DB) pubsub.Subscriber {
var subscriber = MockSubscriber{Options: pubsub.HandlerOptions{
Topic: topic,
Expand Down

0 comments on commit 22eba52

Please sign in to comment.