diff --git a/pkg/api/property.go b/pkg/api/property.go index c9ec812e..13579501 100644 --- a/pkg/api/property.go +++ b/pkg/api/property.go @@ -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) diff --git a/pkg/maintenance/email.go b/pkg/maintenance/email.go index 2bb246a5..14dacf91 100644 --- a/pkg/maintenance/email.go +++ b/pkg/maintenance/email.go @@ -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 } diff --git a/pkg/maintenance/health.go b/pkg/maintenance/health.go index 82e8e984..96cd5391 100644 --- a/pkg/maintenance/health.go +++ b/pkg/maintenance/health.go @@ -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 { diff --git a/pkg/maintenance/license_ee.go b/pkg/maintenance/license_ee.go index 4688514b..fe0db112 100644 --- a/pkg/maintenance/license_ee.go +++ b/pkg/maintenance/license_ee.go @@ -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)