public Worker( WorkerSettings settings, RpcClientFactory rpcClientFactory, IMapping <TKey, TValueIn> mappingPhase, IReducing <TKey, TValueIn, TValueOut> reducingPhase, IPartitioning <TKey, TValueIn> partitioningPhase) { _settings = settings; _mappingPhase = mappingPhase; _reducingPhase = reducingPhase; _partitioningPhase = partitioningPhase; _workerInfoDto = new() { WorkerUuid = settings.WorkerUuid }; _channel = rpcClientFactory.CreateRpcChannel(); _heartBeatTicker = new() { Interval = TimeSpan.FromSeconds(4).TotalMilliseconds }; StartHeartbeat(); } public void Dispose() { _heartBeatTicker.Dispose(); _channel.Dispose(); }
public void StartHeartbeat() { // heart beats var rpcClientHeartbeat = RpcClientFactory.CreateRpcClient(_channel); _heartBeatTicker.Elapsed += (object sender, ElapsedEventArgs e) => _ = SendHeartbeatAsync(rpcClientHeartbeat); _heartBeatTicker.Start(); }
public async Task RunAsync(CancellationToken cancelToken) { // worker tasks if (this.IsWorking) { return; } this.IsWorking = true; var rpcClientWorkTask = RpcClientFactory.CreateRpcClient(_channel); var workTask = Task.Run(() => WorkLoopAsync(rpcClientWorkTask, cancelToken), cancelToken); try { await Task.WhenAll(workTask).ConfigureAwait(false); } finally { this.IsWorking = false; } }