Skip to content

Commit

Permalink
Identify case number before processing
Browse files Browse the repository at this point in the history
Always attempt to identify before processing
to avoid wasting cycles.

Resolves: canonical#43
  • Loading branch information
dosaboy committed Jun 26, 2023
1 parent b7fcf2a commit a653fbf
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/processor/processor.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -186,7 +187,7 @@ 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 {
if err := runner.UploadAndSaveReport(&report, caseNumber, scriptOutputs); err != nil {
logrus.Errorf("cannot upload and save report: %s - error: %s", report.Name, err)
continue
}
Expand Down

0 comments on commit a653fbf

Please sign in to comment.