示例#1
0
        public async Task ResetInProcessing(string uowId)
        {
            var result = await _repository.GetAsync <UowStatus>(uowId);

            if (!result.IsSuccessfull)
            {
                throw new InvalidOperationException($"Retrieval of uow status information for {uowId} failed with message: {result.ErrorMessage} and code: {result.ErrorCode}");
            }

            var retrialWrapper = new UowStatus(result.Item.CurrentRetrialCount, isInProcessing: false);
            await _repository.DeleteAsync(uowId);

            await _repository.CreateAsync(new CreateKVRequest <UowStatus> {
                Item = retrialWrapper, Key = uowId
            });
        }
示例#2
0
        public virtual async Task <IEnumerable <ActionResult> > ClearTryCountAsync(IEnumerable <string> uowIds, CancellationToken cancellationToken)
        {
            var deleteResults = new ConcurrentBag <ActionResult>();

            await uowIds.ForEachAsync(async uowId =>
            {
                var tryCountKey = $"{TryCountKeyPrefix}{uowId}";

                deleteResults.Add(await _repository.DeleteAsync(tryCountKey));
            }, cancellationToken);

            return(deleteResults);
        }
示例#3
0
        public virtual async Task <CentralizedLockItem> TryAcquireAsync(string key)
        {
            var result = await _repository.CreateIfNotExistAsync(new CreateKVRequest <string>
            {
                Item            = Environment.MachineName,
                Key             = key,
                ExpireInSeconds = _timeoutInSeconds,
            });

            if (!result.IsSuccessfull)
            {
                await _logService.LogAsync(Guid.NewGuid().ToString(),
                                           $"An error occurred while trying to create lock entry: [{result.ErrorCode}] {result.ErrorMessage}",
                                           LOG_LEVEL.EXCEPTION, new
                {
                    MachineName  = Environment.MachineName,
                    ServiceName  = "CentralizedLock",
                    ActionName   = "CreateLockEntry",
                    ErrorCode    = result.ErrorCode,
                    ErrorMessage = result.ErrorMessage,
                });

                return(new CentralizedLockItem(() => { }, false));
            }

            return(new CentralizedLockItem(() =>
            {
                if (result.Item)
                {
                    var deleteResult = _repository.DeleteAsync(key).Result;

                    if (!deleteResult.IsSuccessfull)
                    {
                        _logService.LogAsync(Guid.NewGuid().ToString(),
                                             $"An error occurred while trying to delete lock entry: [{result.ErrorCode}] {result.ErrorMessage}",
                                             LOG_LEVEL.EXCEPTION, new
                        {
                            MachineName = Environment.MachineName,
                            ServiceName = "CentralizedLock",
                            ActionName = "DeleteLockEntry",
                            ErrorCode = result.ErrorCode,
                            ErrorMessage = result.ErrorMessage,
                        }).Wait();
                    }
                }
            }, result.Item));
        }