Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(repository): add repository for machine related functions #589

Open
wants to merge 1 commit into
base: next/2.0
Choose a base branch
from

Conversation

renan061
Copy link
Contributor

No description provided.

@renan061 renan061 added this to the 2.0.0 milestone Aug 30, 2024
@renan061 renan061 self-assigned this Aug 30, 2024
@renan061 renan061 changed the base branch from main to feature/machines-map August 30, 2024 21:45
@renan061 renan061 changed the title Feature/advancer repository feat(repository): add repository for machine related functions Aug 30, 2024
return nil, fmt.Errorf("%w (failed querying applications): %w", ErrAdvancerRepository, err)
}

// TODO: missing machine config fields
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove comment. Or am I missing something?

@marcelstanley marcelstanley requested a review from a team September 2, 2024 17:24
"last_processed_block" NUMERIC(20,0) NOT NULL CHECK ("last_processed_block" >= 0 AND "last_processed_block" <= f_maxuint64()),
"status" "ApplicationStatus" NOT NULL,
"iconsensus_address" BYTEA NOT NULL,
-- Temporary -------------------------------------
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Machine config table. And you are missing increment timeouts

MachineIncCycles uint64
MachineMaxCycles uint64
MachineAdvanceTimeout uint32
MachineInspectTimeout uint32
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing increment timeouts. I would follow server-manager config on this.


// ------------------------------------------------------------------------------------------------

func toSqlIn[T fmt.Stringer](a []T) string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function isn't as generic as its signature implies. I suggest falling back to a single type and renaming it or treat the model.Address format before calling it. It would help to add some documentation to it as well.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I'd suggest naming it addressesToSqlInValues

) (map[Address][]*Input, error) {
result := map[Address][]*Input{}
if len(apps) == 0 {
return result, nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional: it would be nice to add a WARN log entry here, as this wouldn't be an expected scenario for this function.

return nil
}

func (repo *MachineRepository) UpdateEpochs(ctx context.Context, app Address) error {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
func (repo *MachineRepository) UpdateEpochs(ctx context.Context, app Address) error {
func (repo *MachineRepository) UpdateProcessedEpochs(ctx context.Context, app Address) error {

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or another non too generic name

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1

`
rows, err := repo.db.Query(ctx, query)
if err != nil {
return nil, fmt.Errorf("%w (failed querying applications): %w", ErrAdvancerRepository, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("%w (failed querying applications): %w", ErrAdvancerRepository, err)
return nil, fmt.Errorf("%w (failed querying machine configurations): %w", ErrAdvancerRepository, err)

return nil
})
if err != nil {
return nil, fmt.Errorf("%w (failed reading rows): %w", ErrAdvancerRepository, err)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return nil, fmt.Errorf("%w (failed reading rows): %w", ErrAdvancerRepository, err)
return nil, fmt.Errorf("%w (failed reading machine configuration rows): %w", ErrAdvancerRepository, err)

Comment on lines +79 to +86
query := fmt.Sprintf(`
SELECT id, index, status, raw_data
FROM input
WHERE application_address = @applicationAddress
AND index >= @index
AND status != 'NONE'
ORDER BY index ASC
`)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
query := fmt.Sprintf(`
SELECT id, index, status, raw_data
FROM input
WHERE application_address = @applicationAddress
AND index >= @index
AND status != 'NONE'
ORDER BY index ASC
`)
query := `
SELECT id, index, status, raw_data
FROM input
WHERE application_address = @applicationAddress
AND index >= @index
AND status != 'NONE'
ORDER BY index ASC
`

WHERE status = 'NONE'
AND application_address IN %s
ORDER BY index ASC, application_address
`, toSqlIn(apps)) // NOTE: not sanitized
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`, toSqlIn(apps)) // NOTE: not sanitized
`, addressesToSqlInValues(apps)) // NOTE: not sanitized

Comment on lines +51 to +61
t.Run("GetProcessedInputs", func(t *testing.T) {
t.Skip("TODO")
})

t.Run("GetUnprocessedInputs", func(t *testing.T) {
t.Skip("TODO")
})

t.Run("StoreAdvanceResult", func(t *testing.T) {
t.Skip("TODO")
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the plan for the pending tests?


// ------------------------------------------------------------------------------------------------

func toSqlIn[T fmt.Stringer](a []T) string {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And I'd suggest naming it addressesToSqlInValues

}

// ------------------------------------------------------------------------------------------------

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some documentation for the next few functions would help.

Base automatically changed from feature/machines-map to next/2.0 September 9, 2024 15:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: 👀 In review
Development

Successfully merging this pull request may close these issues.

5 participants