mirror of
https://github.com/PrivateCaptcha/PrivateCaptcha.git
synced 2026-02-09 07:19:08 -06:00
Respect context cancellation in backoff wait
This commit is contained in:
@@ -311,7 +311,11 @@ func (s *Server) doCreateProperties(ctx context.Context, tlog *slog.Logger, user
|
||||
|
||||
for i, property := range params.Properties {
|
||||
if i > 0 {
|
||||
time.Sleep(b.Duration())
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return results, ctx.Err()
|
||||
case <-time.After(b.Duration()):
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Create properties in batches instead of one by one
|
||||
@@ -733,7 +737,11 @@ func (s *Server) doUpdateProperties(ctx context.Context, tlog *slog.Logger, user
|
||||
|
||||
for i, property := range params.Properties {
|
||||
if i > 0 {
|
||||
time.Sleep(b.Duration())
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return results, ctx.Err()
|
||||
case <-time.After(b.Duration()):
|
||||
}
|
||||
}
|
||||
|
||||
status := s.doUpdateProperty(ctx, tlog.With("index", i), property, user, org)
|
||||
|
||||
@@ -314,7 +314,12 @@ func (j *UserEmailNotificationsJob) processNotificationsChunk(ctx context.Contex
|
||||
for _, n := range notifications {
|
||||
if currSentCount := len(processedNotificationIDs); currSentCount > lastSentCount {
|
||||
// backoff a little not to overwhelm transactional email provider
|
||||
time.Sleep(b.Duration())
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
slog.WarnContext(ctx, "Job context cancelled", common.ErrAttr(ctx.Err()))
|
||||
return processedNotificationIDs
|
||||
case <-time.After(b.Duration()):
|
||||
}
|
||||
lastSentCount = currSentCount
|
||||
}
|
||||
|
||||
|
||||
@@ -85,7 +85,12 @@ func (hc *HealthCheckJob) checkClickHouse(ctx context.Context) int32 {
|
||||
|
||||
for i := 0; i < maxAttempts; i++ {
|
||||
if i > 0 {
|
||||
time.Sleep(b.Duration())
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
slog.WarnContext(ctx, "ClickHouse ping context cancelled", common.ErrAttr(ctx.Err()))
|
||||
return int32(FlagFalse)
|
||||
case <-time.After(b.Duration()):
|
||||
}
|
||||
}
|
||||
|
||||
if err = hc.TimeSeriesDB.Ping(ctx); err == nil {
|
||||
@@ -113,7 +118,12 @@ func (hc *HealthCheckJob) checkPostgres(ctx context.Context) int32 {
|
||||
|
||||
for i := 0; i < maxAttempts; i++ {
|
||||
if i > 0 {
|
||||
time.Sleep(b.Duration())
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
slog.WarnContext(ctx, "Postgres ping context cancelled", common.ErrAttr(ctx.Err()))
|
||||
return int32(FlagFalse)
|
||||
case <-time.After(b.Duration()):
|
||||
}
|
||||
}
|
||||
|
||||
if err = hc.BusinessDB.Ping(ctx); err == nil {
|
||||
|
||||
@@ -201,7 +201,11 @@ func (j *checkLicenseJob) fetchActivation(ctx context.Context) ([]byte, error) {
|
||||
|
||||
for i := 0; i < activationAPIAttempts; i++ {
|
||||
if i > 0 {
|
||||
time.Sleep(b.Duration())
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return data, ctx.Err()
|
||||
case <-time.After(b.Duration()):
|
||||
}
|
||||
}
|
||||
|
||||
data, err = doFetchActivation(ctx, j.url, licenseKey, hwid, j.version)
|
||||
|
||||
Reference in New Issue
Block a user