diff --git a/pkg/common/salesforce.go b/pkg/common/salesforce.go index 9d754b1..cef6f91 100644 --- a/pkg/common/salesforce.go +++ b/pkg/common/salesforce.go @@ -66,10 +66,10 @@ func GetCaseNumberByFilename(filename string) (string, error) { } for _, candidate := range regex.FindAll([]byte(filename), 1) { - if len(candidate) <= 8 { + if len(candidate) <= 8 && len(candidate) > 0 { return string(candidate), nil } } - return "", fmt.Errorf("Not found case number on: %s", filename) + return "", fmt.Errorf("Could not identify case number from filename '%s'", filename) } diff --git a/pkg/processor/processor.go b/pkg/processor/processor.go index 6b6c9a4..837e3e9 100644 --- a/pkg/processor/processor.go +++ b/pkg/processor/processor.go @@ -107,7 +107,7 @@ func RunReport(report *ReportToExecute) (map[string][]byte, error) { const DefaultReportOutputFormat = "%s.athena-%s.%s" -func (runner *ReportRunner) UploadAndSaveReport(report *ReportToExecute, scriptOutputs map[string][]byte) error { +func (runner *ReportRunner) UploadAndSaveReport(report *ReportToExecute, caseNumber string, scriptOutputs map[string][]byte) error { var file db.File var uploadPath string filePath := report.File.Path @@ -124,11 +124,6 @@ func (runner *ReportRunner) UploadAndSaveReport(report *ReportToExecute, scriptO uploadPath = path.Join(runner.Config.Processor.ReportsUploadPath, filepath.Base(filePath)) } - caseNumber, err := common.GetCaseNumberByFilename(filePath) - if err != nil || caseNumber == "" { - return fmt.Errorf("not found case number on filename: %s", filePath) - } - logrus.Infof("Getting case from salesforce number: %s", caseNumber) sfCase, err := runner.SalesforceClient.GetCaseByNumber(caseNumber) if err != nil { @@ -178,6 +173,12 @@ func (runner *ReportRunner) Run(reportFn func(report *ReportToExecute) (map[stri for _, report := range runner.Reports { var err error + caseNumber, err := common.GetCaseNumberByFilename(report.File.Path) + if err != nil || caseNumber == "" { + logrus.Error(err) + continue + } + logrus.Debugf("Running report: %s on file: %s", report.Name, report.File.Path) scriptOutputs, err := reportFn(&report) if err != nil { @@ -186,8 +187,8 @@ func (runner *ReportRunner) Run(reportFn func(report *ReportToExecute) (map[stri } logrus.Debugf("Uploading and saving report:%s script outputs: %d - for file: %s", report.Name, len(scriptOutputs), report.File.Path) - if err := runner.UploadAndSaveReport(&report, scriptOutputs); err != nil { - logrus.Errorf("cannot upload and save report: %s - error: %s", report.Name, err) + if err := runner.UploadAndSaveReport(&report, caseNumber, scriptOutputs); err != nil { + logrus.Errorf("Failed to upload and save report: %s - error: %s", report.Name, err) continue } } diff --git a/pkg/processor/processor_test.go b/pkg/processor/processor_test.go index 7e1902d..7b51b45 100644 --- a/pkg/processor/processor_test.go +++ b/pkg/processor/processor_test.go @@ -57,9 +57,11 @@ func (s *ProcessorTestSuite) TestRunProcessor() { b, _ := json.Marshal(db.File{Path: "/uploads/sosreport-123.tar.xz"}) b1, _ := json.Marshal(db.File{Path: "/uploads/sosreport-321.tar.xz"}) + b2, _ := json.Marshal(db.File{Path: "/uploads/sosreport-abc.tar.xz"}) _ = provider.Publish(context.Background(), "sosreports", &pubsub.Msg{Data: b}) _ = provider.Publish(context.Background(), "sosreports", &pubsub.Msg{Data: b1}) + _ = provider.Publish(context.Background(), "sosreports", &pubsub.Msg{Data: b2}) var called = 0 @@ -79,8 +81,8 @@ func (s *ProcessorTestSuite) TestRunProcessor() { return &subscriber }) - assert.Equal(s.T(), called, 2) - assert.Equal(s.T(), len(provider.Msgs["sosreports"]), 2) + assert.Equal(s.T(), called, 3) + assert.Equal(s.T(), len(provider.Msgs["sosreports"]), 3) } func TestNewProcessor(t *testing.T) {