-
Notifications
You must be signed in to change notification settings - Fork 63
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
base: next/2.0
Are you sure you want to change the base?
Conversation
return nil, fmt.Errorf("%w (failed querying applications): %w", ErrAdvancerRepository, err) | ||
} | ||
|
||
// TODO: missing machine config fields |
There was a problem hiding this comment.
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?
"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 ------------------------------------- |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (repo *MachineRepository) UpdateEpochs(ctx context.Context, app Address) error { | |
func (repo *MachineRepository) UpdateProcessedEpochs(ctx context.Context, app Address) error { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return nil, fmt.Errorf("%w (failed reading rows): %w", ErrAdvancerRepository, err) | |
return nil, fmt.Errorf("%w (failed reading machine configuration rows): %w", ErrAdvancerRepository, err) |
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 | ||
`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`, toSqlIn(apps)) // NOTE: not sanitized | |
`, addressesToSqlInValues(apps)) // NOTE: not sanitized |
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") | ||
}) |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
} | ||
|
||
// ------------------------------------------------------------------------------------------------ | ||
|
There was a problem hiding this comment.
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.
31c55f0
to
cf978c5
Compare
026621d
to
40b2fd7
Compare
No description provided.