public void EndJob(Job job) { Test_JobManager.GetInstance().EndJob(job); var connection = RedisWrapper.GetConnection(Test_Config.Redis_Server); var db = connection.GetDatabase(Test_Config.Redis_DBIndex); //处理数量+1 db.StringIncrement(Test_Config.Job_Customer_Process_Count); }
public void Process(CancellationToken token) { var resetJobTokenSource = new CancellationTokenSource(); StandResetOfflineClientJobsAsync(_resetJobInterval, resetJobTokenSource.Token); var random = new Random(); for (var i = 0; i < 10000; i++) { var delay = random.Next(700, 2000); var job = new Job { Id = i }; Test_JobManager.GetInstance().AddJobToQueue(job); Console.WriteLine($"添加, {job.Id}"); Thread.Sleep(delay); } }
public void ResetOfflineClientJobs(TimeSpan interval) { var clients = ClientManager.GetInstance().GetClients(); var clients_toRemove = new List <Client.Client>(); foreach (var client in clients) { if (client.LastKeepAliveAt != null && client.LastKeepAliveAt < DateTime.Now.Add(-interval)) { //移除客户端 clients_toRemove.Add(client); } } foreach (var client in clients_toRemove) { //重置任务 Test_JobManager.GetInstance().ResetJob_FromClientJobSpace(client.JobSpaceName, false); //删除客户端,不在这里删了 //ClientManager.RemoveClient(client.Setting.ClientId); } }
public void ProcessJob(Job job) { Client.ClientManager.GetInstance().SetJobSpaceData(Client.Client.Instance.JobSpaceName, Test_Config.JobBusiType, job.Id); var random = new Random(); var delay = random.Next(700, 1500); if (random.Next(1, 100) < 60) { Console.WriteLine($"完成, {job.Id}"); FinishJob(job); //清空任务空间 Test_JobManager.GetInstance().ClearClientJobSpace(Client.Client.Instance.JobSpaceName); } else { Console.WriteLine($"失败, {job.Id}"); EndJob(job); Test_JobManager.GetInstance().AddJobToQueue(job, false, true); //清空任务空间 Test_JobManager.GetInstance().ClearClientJobSpace(Client.Client.Instance.JobSpaceName); } Thread.Sleep(delay); }
/// <summary> /// 公众号画像统计_消费者 /// </summary> public void Process(CancellationToken token) { Job job; if (Test_JobManager.GetInstance().TryGetJob_FromClientJobSpace(Client.Client.Instance.JobSpaceName, out job)) { ProcessJob(job); } while (!token.IsCancellationRequested) { if (Test_JobManager.GetInstance().TryGetJob_FromJobQueue(out job)) { ProcessJob(job); } else { Console.WriteLine("没有任务了...\r\n\r\n\r\n"); Thread.Sleep(3000); //break; } } //全部处理完成 }