Skip to content

Commit

Permalink
fix linting initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
bhagatparwinder committed Oct 3, 2024
1 parent 7470d79 commit 69aa08e
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 4 deletions.
4 changes: 2 additions & 2 deletions bcda/service/alr.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
26 changes: 24 additions & 2 deletions optout/local_file_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package optout
import (
"bufio"
"fmt"
"github.com/ccoveille/go-safecast"
"os"
"path/filepath"
"time"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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++
Expand Down Expand Up @@ -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
}

0 comments on commit 69aa08e

Please sign in to comment.