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

Add AvailableCapacity method to SourceManager #1665

Merged
merged 1 commit into from
Aug 29, 2023

Conversation

mcastorina
Copy link
Collaborator

@mcastorina mcastorina commented Aug 25, 2023

Description:

Add AvailableCapacity method to SourceManager to expose the approximate number of goroutines available to run jobs.

Checklist:

  • Tests passing (make test-community)?
  • Lint passing (make lint this requires golangci-lint)?

@mcastorina mcastorina requested a review from a team as a code owner August 25, 2023 19:38
@@ -207,6 +215,16 @@ func (s *SourceManager) ScanChunk(chunk *Chunk) {
s.outputChunks <- chunk
}

// AvailableCapacity returns the number of concurrent jobs the manager can
// accommodate at this time. If there is no limit, -1 is returned.
func (s *SourceManager) AvailableCapacity() int {
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: Could we avoid in-band errors here and return multiple values?
maybe:

func (s *SourceManager) AvailableCapacity() (int, bool) {
	if s.poolLimit == 0 {
		return 0, false
	}
	runCount := atomic.LoadInt32(&s.currentRunningCount)
	return s.poolLimit - int(runCount), true
}

ref: https://google.github.io/styleguide/go/decisions#in-band-errors

@mcastorina mcastorina merged commit 7ba880f into main Aug 29, 2023
9 checks passed
@mcastorina mcastorina deleted the job-ref-available-capacity branch August 29, 2023 19:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants