async Task Retry(PromiseEntry entry) { await Ajax.InternalRequestAsync(entry.Visit, (r, v) => { var entity = PromiseEntity.FromVisit(v); entity.Id = entry.Id; entity.Id = entry.Id; entity.LastRequestTime = DateTime.Now; entity.RequestCount++; entity.IsSuccess = true; entity.Content = r.ToString(); this.Store.UpdateAsync(entity).Start(); }, (e, v) => { Task.Run(async() => { var entity = PromiseEntity.FromVisit(v); entity.Id = entry.Id; entity.LastRequestTime = DateTime.Now; entity.RequestCount++; entity.IsSuccess = false; entity.Exception = e.ToString(); await this.Store.UpdateAsync(entity); lock (this) { _NotCompletes.Enqueue(entry); } }); return(false); }); }
async Task AddToQueueAsync(Visit visit, AdditionInfo info = null) { var entity = new PromiseEntity(visit); var entry = new PromiseEntry() { Visit = visit, Id = entity.Id = Guid.NewGuid(), LastRequestTime = entity.LastRequestTime = entity.CreateTime = DateTime.Now, RetryInternvals = entity.RetryInternvals = 1000, RequestCount = entity.RequestCount = 1 }; if (info != null) { entity.Category = info.Category; entity.BusinessId = info.BusinessId; } await this.Store.CreateAsync(entity); lock (this) { _NotCompletes.Enqueue(entry); if (_Thread == null) { _Thread = new Thread(new ThreadStart(this.Loop)); _Thread.Start(); } } }
public static PromiseEntity FromVisit(Visit visit, PromiseEntity entity = null) { return(null); }