1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950 |
- using CallCenter.Caches;
- using CallCenter.Realtimes;
- using Microsoft.Extensions.DependencyInjection;
- using Microsoft.Extensions.Hosting;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace CallCenter.CacheManager
- {
- public class CallQueueManager : BackgroundService
- {
- private readonly IServiceScopeFactory _serviceScopeFactory;
- private const string CallKey = "CallQueue";
- public CallQueueManager(IServiceScopeFactory serviceScopeFactory)
- {
- _serviceScopeFactory = serviceScopeFactory;
- }
- protected override async Task ExecuteAsync(CancellationToken cancellationToken)
- {
- //work缓存注入
- var userCacheManager = _serviceScopeFactory.CreateScope().ServiceProvider.GetService<IUserCacheManager>();
- //消息通知注入
- var realtimeService = _serviceScopeFactory.CreateScope().ServiceProvider.GetService<IRealtimeService>();
- //CallQueue缓存注入
- var callQueueManager = _serviceScopeFactory.CreateScope().ServiceProvider.GetService<ICallCacheManager>();
- var time = TimeSpan.FromSeconds(1);
- while (!cancellationToken.IsCancellationRequested)
- {
- //查询当前队列
- var callList = callQueueManager.GetCallQueueList();
- if (callList ==null)
- {
- callList = new List<Calls.Call>();
- }
- //通知
- await realtimeService.CallQueueAsync(callList, cancellationToken);
- await Task.Delay(time, cancellationToken);
- }
-
- }
- }
- }
|