private void InvokeCleanupIfNeeded()

in src/Covi/Features/BluetoothTracing/DeviceProcessor/Internal/DefaultDeviceProcessor.cs [51:86]


        private void InvokeCleanupIfNeeded()
        {
            if (((DateTime.UtcNow - _lastCleanupTime) <= Configuration.Constants.BluetoothConstants.DeviceThrottleTime))
            {
                return;
            }

            Task.Run(() =>
            {
                if (!Monitor.TryEnter(_cleanupLock))
                {
                    return;
                }

                try
                {
                    if (((DateTime.UtcNow - _lastCleanupTime) <= Configuration.Constants.BluetoothConstants.DeviceThrottleTime))
                    {
                        return;
                    }

                    _logger.LogDebug($"DeviceProcessor - Cleanup started.");
                    var minPurgeDate = DateTime.UtcNow - Configuration.Constants.BluetoothConstants.DataExpirationTime;
                    _tracesStorage.Purge(minPurgeDate);
                    _lastCleanupTime = DateTime.UtcNow;
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, $"DeviceProcessor -  Cleanup failed.");
                }
                finally
                {
                    Monitor.Exit(_cleanupLock);
                }
            });
        }