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; } }
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(); }
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); }
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)); }
public async Task UpdateErrorMessage(DTOperationRecord record, string errorMessage) { await _dtOperationRecordStore.UpdateErroeMessage(record.StoreGroupName, record.HashInfo, record.ID, errorMessage); }
public async Task Delete(DTOperationRecord record) { await _dtOperationRecordStore.Delete(record.StoreGroupName, record.HashInfo, record.ID); }
public async Task Add(DTOperationRecord record) { await _dtOperationRecordStore.Add(record); }