diff --git a/bcda/service/alr.go b/bcda/service/alr.go index 5eabd42e6..82e0e11db 100644 --- a/bcda/service/alr.go +++ b/bcda/service/alr.go @@ -6,14 +6,14 @@ import ( "github.com/CMSgov/bcda-app/bcda/models" ) -// Get the MBIs and put them into jobs +// GetAlrJobs Get the MBIs and put them into jobs func (s *service) GetAlrJobs(ctx context.Context, alrMBI *models.AlrMBIs) []*models.JobAlrEnqueueArgs { partition := int(s.alrMBIsPerJob) loop := len(alrMBI.MBIS) / partition - bigJob := []*models.JobAlrEnqueueArgs{} + var bigJob []*models.JobAlrEnqueueArgs for i := 0; i < loop; i++ { bigJob = append(bigJob, &models.JobAlrEnqueueArgs{ diff --git a/go.mod b/go.mod index 90aff603d..1b0645244 100644 --- a/go.mod +++ b/go.mod @@ -50,6 +50,7 @@ require ( github.com/Microsoft/go-winio v0.4.17-0.20210211115548-6eac466e5fa3 // indirect github.com/bmizerany/perks v0.0.0-20141205001514-d9a9656a3a4b // indirect github.com/c2h5oh/datasize v0.0.0-20200825124411-48ed595a09d2 // indirect + github.com/ccoveille/go-safecast v1.1.0 // indirect github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect github.com/davecgh/go-spew v1.1.1 // indirect github.com/denisenkom/go-mssqldb v0.9.0 // indirect diff --git a/go.sum b/go.sum index 90016efc8..033249210 100644 --- a/go.sum +++ b/go.sum @@ -143,6 +143,8 @@ github.com/boombuler/barcode v1.0.0/go.mod h1:paBWMcWSl3LHKBqUq+rly7CNSldXjb2rDl github.com/buger/jsonparser v0.0.0-20200322175846-f7e751efca13/go.mod h1:tgcrVJ81GPSF0mz+0nu1Xaz0fazGPrmmJfJtxjbHhUQ= github.com/c2h5oh/datasize v0.0.0-20200825124411-48ed595a09d2 h1:t8KYCwSKsOEZBFELI4Pn/phbp38iJ1RRAkDFNin1aak= github.com/c2h5oh/datasize v0.0.0-20200825124411-48ed595a09d2/go.mod h1:S/7n9copUssQ56c7aAgHqftWO4LTf4xY6CGWt8Bc+3M= +github.com/ccoveille/go-safecast v1.1.0 h1:iHKNWaZm+OznO7Eh6EljXPjGfGQsSfa6/sxPlIEKO+g= +github.com/ccoveille/go-safecast v1.1.0/go.mod h1:QqwNjxQ7DAqY0C721OIO9InMk9zCwcsO7tnRuHytad8= github.com/cenkalti/backoff/v4 v4.0.2/go.mod h1:eEew/i+1Q6OrCDZh3WiXYv3+nJwBASZ8Bog/87DQnVg= github.com/cenkalti/backoff/v4 v4.1.3 h1:cFAlzYUlVYDysBEH2T5hyJZMh3+5+WCBvSnK6Q8UtC4= github.com/cenkalti/backoff/v4 v4.1.3/go.mod h1:scbssz8iZGpm3xbr14ovlUdkxfGXNInqkPWOWmG2CLw= diff --git a/optout/local_file_handler.go b/optout/local_file_handler.go index 9e27025b3..1c5220fd6 100644 --- a/optout/local_file_handler.go +++ b/optout/local_file_handler.go @@ -3,6 +3,7 @@ package optout import ( "bufio" "fmt" + "github.com/ccoveille/go-safecast" "os" "path/filepath" "time" @@ -53,7 +54,11 @@ func (handler *LocalFileHandler) getOptOutFileMetadata(suppresslist *[]*OptOutFi handler.Logger.Errorf("Unknown file found: %s", metadata) *skipped = *skipped + 1 - deleteThreshold := time.Hour * time.Duration(handler.FileArchiveThresholdHr) + f, e, done := convertFileArchiveThreshold(handler) + if done { + return e + } + deleteThreshold := time.Hour * time.Duration(f) if metadata.DeliveryDate.Add(deleteThreshold).Before(time.Now()) { newpath := fmt.Sprintf("%s/%s", handler.PendingDeletionDir, info.Name()) err = os.Rename(metadata.FilePath, newpath) @@ -100,7 +105,12 @@ func (handler *LocalFileHandler) CleanupOptOutFiles(suppresslist []*OptOutFilena // check the timestamp on the failed files elapsed := time.Since(suppressionFile.DeliveryDate).Hours() - if int(elapsed) > int(handler.FileArchiveThresholdHr) { + f, err, done := convertFileArchiveThreshold(handler) + if done { + return err + } + + if int(elapsed) > int(f) { err := os.Rename(suppressionFile.FilePath, newpath) if err != nil { errCount++ @@ -131,3 +141,15 @@ func (handler *LocalFileHandler) CleanupOptOutFiles(suppresslist []*OptOutFilena } return nil } + +func convertFileArchiveThreshold(handler *LocalFileHandler) (int64, error, bool) { + f, err := safecast.ToInt64(handler.FileArchiveThresholdHr) + if err != nil { + errmsg := fmt.Sprintf("error converting FileArchiveThresholdHr to int64: %v", handler.FileArchiveThresholdHr) + err = errors.Wrap(err, errmsg) + fmt.Println(errmsg) + handler.Logger.Error(err) + return 0, err, true + } + return f, nil, false +}