From 3f55408f9064b90b545ed690ff8f972aa92708ec Mon Sep 17 00:00:00 2001 From: Richard Hallett Date: Mon, 5 Feb 2024 13:51:06 +0100 Subject: [PATCH] Send compressed json via worker --- cmd/worker/main.go | 18 +++++++++--------- internal/app/reports/service.go | 3 +-- 2 files changed, 10 insertions(+), 11 deletions(-) diff --git a/cmd/worker/main.go b/cmd/worker/main.go index 5cdb369..a2ee45f 100644 --- a/cmd/worker/main.go +++ b/cmd/worker/main.go @@ -67,20 +67,20 @@ func report_job(repoId string, beginDate time.Time, endDate time.Time, platform } // Write report to file - filename := "report_" + repoId + "_" + beginDate.Format("2006-01-02") + "_" + endDate.Format("2006-01-02") + "_" + platform + "_" + publisher + "_" + publisherId + "_" + string(index) + ".json" - file, err := os.Create(filename) - if err != nil { - return err - } - defer file.Close() + // filename := "report_" + repoId + "_" + beginDate.Format("2006-01-02") + "_" + endDate.Format("2006-01-02") + "_" + platform + "_" + publisher + "_" + publisherId + "_" + string(index) + ".json" + // file, err := os.Create(filename) + // if err != nil { + // return err + // } + // defer file.Close() - file.Write(reportJson) + //file.Write(reportJson) // Gzip json - //compressedJson, _ := gzipData(reportJson) + compressedJson, _ := gzipData(reportJson) // Send to Reports API - err = reports.SendReportToAPI(reportsAPIEndpoint, reportJson, config.DataCite.JWT) + err = reports.SendReportToAPI(reportsAPIEndpoint, compressedJson, config.DataCite.JWT) if err != nil { return err diff --git a/internal/app/reports/service.go b/internal/app/reports/service.go index 76f43b6..1204515 100644 --- a/internal/app/reports/service.go +++ b/internal/app/reports/service.go @@ -232,8 +232,7 @@ func SendReportToAPI(reportsAPIEndpoint string, compressedJson []byte, jwt strin } // Set content type to be gzip as report will be compressed - //req.Header.Set("Content-Type", "application/gzip") - req.Header.Set("Content-Type", "application/json") + req.Header.Set("Content-Type", "application/gzip") // Add JWT token to request req.Header.Set("Authorization", "Bearer " + jwt)