Ejemplo n.º 1
0
        public async Task Execute(DTOperationRecord record, Func <Task> action)
        {
            try
            {
                await using (DBTransactionScope scope = new DBTransactionScope(System.Transactions.TransactionScopeOption.Required, new System.Transactions.TransactionOptions()
                {
                    IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted, Timeout = new TimeSpan(0, 0, 10)
                }))
                {
                    await _dtOperationRecordStore.UpdateVersion(record.StoreGroupName, record.HashInfo, record.ID, Guid.NewGuid().ToString());

                    await action();

                    await _dtOperationRecordStore.UpdateStatus(record.StoreGroupName, record.HashInfo, record.ID, (int)DTOperationRecordStatus.Complete);

                    scope.Complete();
                }
            }
            catch
            {
                var nRecord = await _dtOperationRecordStore.QueryByID(record.StoreGroupName, record.HashInfo, record.ID);

                if (nRecord != null)
                {
                    await nRecord.Cancel();
                }
                throw;
            }
        }
Ejemplo n.º 2
0
        public async Task Execute(string name, string storeGroupName, string hashInfo, string type, string typeInfo, int timeout, Func <Task> action)
        {
            var record = await _dtOperationRecordRepository.QueryByUniqueName(storeGroupName, hashInfo, name);

            if (record != null)
            {
                await record.Cancel();

                await record.Delete();
            }

            record = new DTOperationRecord()
            {
                HashInfo       = hashInfo,
                Status         = (int)DTOperationRecordStatus.UnComplete,
                StoreGroupName = storeGroupName,
                UniqueName     = name,
                Timeout        = timeout,
                Type           = type,
                TypeInfo       = typeInfo,
                Version        = Guid.NewGuid().ToString()
            };
            await record.Add();

            await record.Execute(action);

            await record.Delete();
        }
Ejemplo n.º 3
0
        public async Task Cancel(DTOperationRecord record)
        {
            var service = getService(record.Type);
            await service.Cancel(record.TypeInfo, record.UniqueName);

            await _dtOperationRecordStore.UpdateStatus(record.StoreGroupName, record.HashInfo, record.ID, (int)DTOperationRecordStatus.Complete);
        }
Ejemplo n.º 4
0
        public async Task <bool> NeedCancel(DTOperationRecord record)
        {
            //先判断是否完成
            if (record.Status == (int)DTOperationRecordStatus.Complete)
            {
                return(await Task.FromResult(false));
            }
            //再判断是否在处理中
            var latestRecord = await _dtOperationRecordStore.QueryByIDNoLock(record.StoreGroupName, record.HashInfo, record.ID);

            if (record.Version != latestRecord.Version)
            {
                return(await Task.FromResult(false));
            }
            //再判断是否超时
            if ((DateTime.UtcNow - record.ModifyTime).TotalSeconds < record.Timeout)
            {
                return(await Task.FromResult(false));
            }


            return(await Task.FromResult(true));
        }
Ejemplo n.º 5
0
 public async Task UpdateErrorMessage(DTOperationRecord record, string errorMessage)
 {
     await _dtOperationRecordStore.UpdateErroeMessage(record.StoreGroupName, record.HashInfo, record.ID, errorMessage);
 }
Ejemplo n.º 6
0
 public async Task Delete(DTOperationRecord record)
 {
     await _dtOperationRecordStore.Delete(record.StoreGroupName, record.HashInfo, record.ID);
 }
Ejemplo n.º 7
0
 public async Task Add(DTOperationRecord record)
 {
     await _dtOperationRecordStore.Add(record);
 }