mirror of
https://github.com/ivuorinen/gibidify.git
synced 2026-01-26 03:24:05 +00:00
* chore(ci): update go to 1.25, add permissions and envs * fix(ci): update pr-lint.yml * chore: update go, fix linting * fix: tests and linting * fix(lint): lint fixes, renovate should now pass * fix: updates, security upgrades * chore: workflow updates, lint * fix: more lint, checkmake, and other fixes * fix: more lint, convert scripts to POSIX compliant * fix: simplify codeql workflow * tests: increase test coverage, fix found issues * fix(lint): editorconfig checking, add to linters * fix(lint): shellcheck, add to linters * fix(lint): apply cr comment suggestions * fix(ci): remove step-security/harden-runner * fix(lint): remove duplication, apply cr fixes * fix(ci): tests in CI/CD pipeline * chore(lint): deduplication of strings * fix(lint): apply cr comment suggestions * fix(ci): actionlint * fix(lint): apply cr comment suggestions * chore: lint, add deps management
37 lines
761 B
Go
37 lines
761 B
Go
package fileproc
|
|
|
|
import (
|
|
"context"
|
|
"time"
|
|
|
|
"github.com/sirupsen/logrus"
|
|
)
|
|
|
|
// WaitForRateLimit waits for rate limiting if enabled.
|
|
func (rm *ResourceMonitor) WaitForRateLimit(ctx context.Context) error {
|
|
if !rm.enabled || rm.rateLimitFilesPerSec <= 0 {
|
|
return nil
|
|
}
|
|
|
|
select {
|
|
case <-ctx.Done():
|
|
return ctx.Err()
|
|
case <-rm.rateLimitChan:
|
|
return nil
|
|
case <-time.After(time.Second): // Fallback timeout
|
|
logrus.Warn("Rate limiting timeout exceeded, continuing without rate limit")
|
|
return nil
|
|
}
|
|
}
|
|
|
|
// rateLimiterRefill refills the rate limiting channel periodically.
|
|
func (rm *ResourceMonitor) rateLimiterRefill() {
|
|
for range rm.rateLimiter.C {
|
|
select {
|
|
case rm.rateLimitChan <- struct{}{}:
|
|
default:
|
|
// Channel is full, skip
|
|
}
|
|
}
|
|
}
|