Skip to content

Commit

Permalink
fix linting issues
Browse files Browse the repository at this point in the history
  • Loading branch information
bhagatparwinder committed Oct 4, 2024
1 parent 80d8227 commit 9dc7539
Show file tree
Hide file tree
Showing 9 changed files with 85 additions and 16 deletions.
9 changes: 8 additions & 1 deletion bcda/cclf/utils/cclfUtils.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/CMSgov/bcda-app/conf"
"github.com/CMSgov/bcda-app/log"
"github.com/CMSgov/bcda-app/optout"
"github.com/ccoveille/go-safecast"
)

// ImportCCLFPackage will copy the appropriate synthetic CCLF files, rename them,
Expand Down Expand Up @@ -129,11 +130,17 @@ func ImportCCLFPackage(acoSize, environment string, fileType models.CCLFFileType

_ = zipWriter.Close()

hours, err:= safecast.ToUint(utils.GetEnvInt("FILE_ARCHIVE_THRESHOLD_HR", 72))

if err != nil {
return err
}

file_processor := &cclf.LocalFileProcessor{
Handler: optout.LocalFileHandler{
Logger: log.API,
PendingDeletionDir: conf.GetEnv("PENDING_DELETION_DIR"),
FileArchiveThresholdHr: uint(utils.GetEnvInt("FILE_ARCHIVE_THRESHOLD_HR", 72)),
FileArchiveThresholdHr: hours,
},
}

Expand Down
10 changes: 9 additions & 1 deletion bcda/models/postgres/alr.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"github.com/CMSgov/bcda-app/bcda/models"
"github.com/CMSgov/bcda-app/bcda/utils"
"github.com/CMSgov/bcda-app/log"
"github.com/ccoveille/go-safecast"
"github.com/jackc/pgx"
"github.com/jackc/pgx/pgtype"
"github.com/jackc/pgx/stdlib"
Expand Down Expand Up @@ -221,7 +222,14 @@ func (r *AlrRepository) GetAlr(ctx context.Context, metakey int64, MBIs []string
return nil, err
}
alr.KeyValue = keyValue
alr.MetaKey = uint(metakey)

key, err:= safecast.ToUint(metakey)

if err != nil {
return nil, err
}

alr.MetaKey = key
alrs = append(alrs, &alr)
}

Expand Down
9 changes: 8 additions & 1 deletion bcda/responseutils/v2/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (
"github.com/CMSgov/bcda-app/bcda/models"
"github.com/CMSgov/bcda-app/conf"
"github.com/CMSgov/bcda-app/log"
"github.com/ccoveille/go-safecast"

"github.com/google/fhir/go/fhirversion"
"github.com/google/fhir/go/jsonformat"
Expand Down Expand Up @@ -68,9 +69,15 @@ func CreateJobsBundle(jobs []*models.Job, host string) *fhirmodelCR.Bundle {
entries = append(entries, entry)
}

jobLength, err := safecast.ToUint32(len(jobs))

if err != nil {
log.API.Errorln(err)
}

return &fhirmodelCR.Bundle{
Type: &fhirmodelCR.Bundle_TypeCode{Value: fhircodes.BundleTypeCode_SEARCHSET},
Total: &fhirdatatypes.UnsignedInt{Value: uint32(len(jobs))},
Total: &fhirdatatypes.UnsignedInt{Value: jobLength},
Entry: entries,
}
}
Expand Down
9 changes: 8 additions & 1 deletion bcda/responseutils/writer.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/CMSgov/bcda-app/conf"
"github.com/CMSgov/bcda-app/log"
logAPI "github.com/CMSgov/bcda-app/log"
"github.com/ccoveille/go-safecast"

"github.com/google/fhir/go/fhirversion"
"github.com/google/fhir/go/jsonformat"
Expand Down Expand Up @@ -64,9 +65,15 @@ func CreateJobsBundle(jobs []*models.Job, host string) *fhirmodels.Bundle {
entries = append(entries, entry)
}

jobLength, err := safecast.ToUint32(len(jobs))

if err != nil {
log.API.Errorln(err)
}

return &fhirmodels.Bundle{
Type: &fhircodes.BundleTypeCode{Value: fhircodes.BundleTypeCode_SEARCHSET},
Total: &fhirdatatypes.UnsignedInt{Value: uint32(len(jobs))},
Total: &fhirdatatypes.UnsignedInt{Value: jobLength},
Entry: entries,
}
}
Expand Down
8 changes: 7 additions & 1 deletion bcda/service/alr.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,18 @@ import (
"context"

"github.com/CMSgov/bcda-app/bcda/models"
"github.com/CMSgov/bcda-app/log"
"github.com/ccoveille/go-safecast"
)

// 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)
partition, err := safecast.ToInt(s.alrMBIsPerJob)

if err != nil {
log.API.Errorln(err)
}

loop := len(alrMBI.MBIS) / partition

Expand Down
7 changes: 6 additions & 1 deletion bcda/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"strings"
"time"

"github.com/ccoveille/go-safecast"
"github.com/pborman/uuid"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -293,8 +294,12 @@ func (s *service) createQueueJobs(ctx context.Context, conditions RequestConditi
}
if resource, ok := GetDataType(rt); ok {
if resource.SupportsDataType(dataType) {
jobId, err := safecast.ToInt(conditions.JobID)
if err != nil {
log.API.Errorln(err)
}
enqueueArgs := models.JobEnqueueArgs{
ID: int(conditions.JobID),
ID: jobId,
ACOID: conditions.ACOID.String(),
CMSID: conditions.CMSID,
BeneficiaryIDs: jobIDs,
Expand Down
17 changes: 15 additions & 2 deletions bcdaworker/queueing/enqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"github.com/CMSgov/bcda-app/bcda/database"
"github.com/CMSgov/bcda-app/bcda/models"
"github.com/bgentry/que-go"
"github.com/ccoveille/go-safecast"
)

const (
Expand All @@ -32,10 +33,16 @@ func (q queEnqueuer) AddJob(job models.JobEnqueueArgs, priority int) error {
return err
}

p, e := safecast.ToInt16(priority)

if e != nil {
return e
}

j := &que.Job{
Type: QUE_PROCESS_JOB,
Args: args,
Priority: int16(priority),
Priority: int16(p),
}

return q.Enqueue(j)
Expand All @@ -48,10 +55,16 @@ func (q queEnqueuer) AddAlrJob(job models.JobAlrEnqueueArgs, priority int) error
return err
}

p, e := safecast.ToInt16(priority)

if e != nil {
return e
}

j := &que.Job{
Type: ALR_JOB,
Args: args,
Priority: int16(priority),
Priority: int16(p),
}

return q.Enqueue(j)
Expand Down
15 changes: 11 additions & 4 deletions bcdaworker/queueing/manager/que.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/CMSgov/bcda-app/conf"
"github.com/CMSgov/bcda-app/log"
"github.com/bgentry/que-go"
"github.com/ccoveille/go-safecast"
"github.com/jackc/pgx"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
Expand Down Expand Up @@ -118,6 +119,11 @@ func (q *queue) processJob(queJob *que.Job) error {
ctx = log.NewStructuredLoggerEntry(log.Worker, ctx)
ctx, _ = log.SetCtxLogger(ctx, "job_id", jobArgs.ID)
ctx, logger := log.SetCtxLogger(ctx, "transaction_id", jobArgs.TransactionID)
id, e := safecast.ToUint(jobArgs.ID)

if e != nil {
return e
}

exportJob, err := q.worker.ValidateJob(ctx, queJob.ID, jobArgs)
if goerrors.Is(err, worker.ErrParentJobCancelled) {
Expand Down Expand Up @@ -146,10 +152,11 @@ func (q *queue) processJob(queJob *que.Job) error {
logger.Warnf("No job found for ID: %d acoID: %s. Will retry.", jobArgs.ID, jobArgs.ACOID)
return errors.Wrap(repository.ErrJobNotFound, "could not retrieve job from database")
} else if goerrors.Is(err, worker.ErrQueJobProcessed) {
logger.Warnf("Queue job (que_jobs.id) %d already processed for job.id %d. Checking completion status and removing queuejob from que.", queJob.ID, jobArgs.ID)
_, err := worker.CheckJobCompleteAndCleanup(ctx, q.repository, uint(jobArgs.ID))
logger.Warnf("Queue job (que_jobs.id) %d already processed for job.id %d. Checking completion status and removing queuejob from que.", queJob.ID, id)

_, err := worker.CheckJobCompleteAndCleanup(ctx, q.repository, id)
if err != nil {
return errors.Wrap(err, fmt.Sprintf("Error checking job completion & cleanup for job id %d", jobArgs.ID))
return errors.Wrap(err, fmt.Sprintf("Error checking job completion & cleanup for job id %d", id))
}
return nil
} else if err != nil {
Expand All @@ -159,7 +166,7 @@ func (q *queue) processJob(queJob *que.Job) error {
}

// start a goroutine that will periodically check the status of the parent job
go checkIfCancelled(ctx, q.repository, cancel, uint(jobArgs.ID), 15)
go checkIfCancelled(ctx, q.repository, cancel, id, 15)

if err := q.worker.ProcessJob(ctx, queJob.ID, *exportJob, jobArgs); err != nil {
err := errors.Wrap(err, "failed to process job")
Expand Down
17 changes: 13 additions & 4 deletions bcdaworker/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
"github.com/CMSgov/bcda-app/bcdaworker/repository/postgres"
"github.com/CMSgov/bcda-app/conf"
"github.com/CMSgov/bcda-app/log"
"github.com/ccoveille/go-safecast"
"github.com/sirupsen/logrus"

fhircodes "github.com/google/fhir/go/proto/google/fhir/proto/stu3/codes_go_proto"
Expand All @@ -48,7 +49,11 @@ func (w *worker) ValidateJob(ctx context.Context, queJobID int64, jobArgs models
if len(jobArgs.BBBasePath) == 0 {
return nil, ErrNoBasePathSet
}
exportJob, err := w.r.GetJobByID(ctx, uint(jobArgs.ID))
id, err := safecast.ToUint(jobArgs.ID)
if err != nil {
return nil, err
}
exportJob, err := w.r.GetJobByID(ctx, id)
if goerrors.Is(err, repository.ErrJobNotFound) {
return nil, ErrParentJobNotFound
} else if err != nil {
Expand All @@ -63,7 +68,7 @@ func (w *worker) ValidateJob(ctx context.Context, queJobID int64, jobArgs models
return nil, ErrParentJobFailed
}

_, err = w.r.GetJobKey(ctx, uint(jobArgs.ID), queJobID)
_, err = w.r.GetJobKey(ctx, id, queJobID)
if goerrors.Is(err, repository.ErrJobKeyNotFound) {
// No job key exists, which means this queue job needs to be processed.
return exportJob, nil
Expand Down Expand Up @@ -237,7 +242,11 @@ func CloseOrLogError(logger logrus.FieldLogger, f *os.File) {
func writeBBDataToFile(ctx context.Context, r repository.Repository, bb client.APIClient,
cmsID string, queJobID int64, jobArgs models.JobEnqueueArgs, tmpDir string) (jobKeys []models.JobKey, err error) {

jobKeys = append(jobKeys, models.JobKey{JobID: uint(jobArgs.ID), QueJobID: &queJobID, FileName: models.BlankFileName, ResourceType: jobArgs.ResourceType})
id, err := safecast.ToUint(jobArgs.ID)
if err != nil {
return nil, err
}
jobKeys = append(jobKeys, models.JobKey{JobID: id, QueJobID: &queJobID, FileName: models.BlankFileName, ResourceType: jobArgs.ResourceType})

logger := log.GetCtxLogger(ctx)
close := metrics.NewChild(ctx, "writeBBDataToFile")
Expand Down Expand Up @@ -370,7 +379,7 @@ func writeBBDataToFile(ctx context.Context, r repository.Repository, bb client.A
}

if errorCount > 0 {
jobKeys = append(jobKeys, models.JobKey{JobID: uint(jobArgs.ID), QueJobID: &queJobID, FileName: fileUUID + "-error.ndjson", ResourceType: jobArgs.ResourceType})
jobKeys = append(jobKeys, models.JobKey{JobID: id, QueJobID: &queJobID, FileName: fileUUID + "-error.ndjson", ResourceType: jobArgs.ResourceType})
}
return jobKeys, nil
}
Expand Down

0 comments on commit 9dc7539

Please sign in to comment.