Respect context cancellation in backoff wait

This commit is contained in:
Taras Kushnir
2026-01-20 18:38:26 +02:00
parent 469192451e
commit 4f8d2a9ff0
4 changed files with 33 additions and 6 deletions

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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)