//Burada Scan' e NanoServiceBase' in proportylerini ata. protected WorkerServiceBase(Kamaji.Worker.IWorker worker, ScanModel model) : base(false, WorkerObserver.Instance) { this.Model = model ?? throw new ArgumentNullException(nameof(model)); this.Worker = worker ?? throw new ArgumentNullException(nameof(worker)); this.Interval = TimeSpan.FromMilliseconds(model.Period); this.NotifyInfoProvider = new Func <NotifyInfo>(() => new NotifyInfo { Key = this.GetType().Name, Args = this.Model }); }
protected override async Task Execute(IObserver observer, CancellationToken cancellationToken) { ScanModel scan = null; using (var tran = Queue.Instance.StartTransaction <ScanModel>()) { scan = tran.Dequeue(); // observer.Notify("QueueService", "Kuyruktan scan seçildi.", null); if (null != scan) //Yani kuyrukta veri varsa. { Kamaji.Worker.IWorker worker = await Workers.Instance.GetWorker(scan); //öncelikle preReq ve Resource initi edilsin. Sonra zaten scan verip tekrar aldığımızda init olsun kaynaklar. observer.Notify("QueueService", "Worker Alındı", null); WorkerServiceBase service = WorkerServiceList.Instance.Find(scan); if (null == service) { service = WorkerServiceFactory.Create(worker, scan); WorkerServiceList.Instance.Add(service); observer.Notify("QueueService", "Servis ilk defa oluşturuldu", null); } if (service.IsRunning) { tran.Enqueue(scan);//running ise tekrardan kuyruğa ekle. observer.Notify("QueueService", "Servis Runnig olduğu için tekrara kuyruğa eklendi. ", null); } else { _ = service.Start();//başlat bir an önceki commit yapabilelim. like Python. } } //else // observer.Notify("QueueService", "Kuyrukta Scan yok.", null); tran.Commit(); } }