private async Task ProcessQueue(string topic, BackgroundProcessContext context) { var startProcessTime = DateTime.Now; int deleteCount = 0; var length = 0; var start = BatchCount * -1; var end = -1; do { var list = await _redisStorage.GetErrorJobId(topic, start, end);// -100,-1 //从队列的尾部抓取 -1=最后一个,-2=倒数第二个,... length = list.Length; if (context.IsShutdownRequested) { return; } deleteCount = await ProcessFailedJob(topic, list);//倒序处理 end = 0 - (length + 1 - deleteCount); start = end - BatchCount + 1; if (DateTime.Now - startProcessTime >= lockTimeSpan) { break; } }while (length > 0); }