Example #1
0
        public async Task ExecuteAsync(CleanUpAssetFilesCommand command, IExecutionContext executionContext)
        {
            // We use the distributed lock manager to make sure we don't have two
            // processes running at the same time trying to clean up the same files.
            var distributedLock = await _distributedLockManager.LockAsync <CleanUpAssetFilesCommandDistributedLockDefinition>();

            if (distributedLock.IsLockedByAnotherProcess())
            {
                _logger.LogInformation($"{nameof(CleanUpAssetFilesCommandHandler)} requested to be run, but is already locked by another process.");

                return;
            }

            try
            {
                var queueItems = await GetQueueBatch(command.BatchSize, executionContext);

                if (queueItems.Any())
                {
                    await ProcessQueueAsync(queueItems);
                }
            }
            finally
            {
                await _distributedLockManager.UnlockAsync(distributedLock);
            }
        }
Example #2
0
 public Task UnlockAsync(DistributedLock distributedLock)
 {
     return(_distributedLockManager.UnlockAsync(distributedLock));
 }