Skip to content

Commit

Permalink
DEVPROD-12560 Remove RetryMarshalBSON on project parser struct (#8497)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZackarySantana authored Nov 21, 2024
1 parent 6f6b2db commit 1402089
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 32 deletions.
30 changes: 0 additions & 30 deletions model/project_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,36 +162,6 @@ func (pp *ParserProject) MarshalBSON() ([]byte, error) {
return mgobson.Marshal(pp)
}

// RetryMarshalBSON marshals the BSON and attempts to unmarshal it back to make sure
// it is valid. It only retries when it fails at reading the BSON, not if it encountered
// an error while marshalling.
func (pp *ParserProject) RetryMarshalBSON(retries int) ([]byte, error) {
return pp.retryMarshalBSON(retries, retries)
}

func (pp *ParserProject) retryMarshalBSON(maxRetries, retries int) ([]byte, error) {
projBytes, err := bson.Marshal(pp)
if err != nil {
return nil, errors.Wrap(err, "marshalling project")
}
_, err = GetProjectFromBSON(projBytes)
if err != nil {
if retries > 0 {
return pp.retryMarshalBSON(maxRetries, retries-1)
}
return nil, errors.Wrap(err, "unmarshalling project to verify it's integrity")
}
// TODO (DEVPROD-12560): Remove this log line, potentially the whole retry if it's
// never been logged since that means the retries are never actually happening.
if retries < maxRetries {
grip.Debug(message.Fields{
"message": "parser project marshalling succeeded after retries",
"retries": maxRetries - retries,
})
}
return projBytes, nil
}

func (pp *ParserProject) MarshalYAML() (interface{}, error) {
for i, pt := range pp.Tasks {
for j := range pt.Commands {
Expand Down
2 changes: 1 addition & 1 deletion model/project_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2990,7 +2990,7 @@ func TestMarshalBSON(t *testing.T) {
Identifier: utility.ToStringPtr("small"),
}

encoded, err := pp.RetryMarshalBSON(5)
encoded, err := pp.MarshalBSON()
require.NoError(t, err)
require.NotEmpty(t, encoded)

Expand Down
2 changes: 1 addition & 1 deletion rest/route/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ func (h *getParserProjectHandler) Run(ctx context.Context) gimlet.Responder {
Message: fmt.Sprintf("parser project '%s' not found", v.Id),
})
}
projBytes, err := pp.RetryMarshalBSON(5)
projBytes, err := pp.MarshalBSON()
if err != nil {
return gimlet.MakeJSONInternalErrorResponder(errors.Wrap(err, "marshalling project bytes to bson"))
}
Expand Down

0 comments on commit 1402089

Please sign in to comment.