public async Task Commit(params object[] e) { _env.Debug($"Commit '{string.Join(", ", e)}' to {_endpoint}"); using (var conn = await _env.Connect(_endpoint)) { await conn.Write(new CommitRequest(e)); await conn.Read(5.Sec()); } }
async Task <TResponse> Unary <TRequest, TResponse>(TRequest req) { var now = _env.Time; foreach (var(i, ts, mark) in GetEndpoints()) { var endpoint = _endpoints[i]; _env.Debug($"Send '{req}' to {endpoint}"); if (ts != TimeSpan.Zero) { await _env.Delay(ts, _env.Token); } try { using (var conn = await _env.Connect(endpoint)) { await conn.Write(req); var res = await conn.Read(5.Sec()); if (res is ArgumentException ex) { throw new ArgumentException(ex.Message); } return((TResponse)res); } } catch (IOException ex) { if (!mark) { _env.Warning($"! {ex.Message} for '{req}'. Retrying {endpoint}"); continue; } if (_outages[i] > now) { _env.Warning($"! {ex.Message} for '{req}'. {endpoint} already DOWN"); } else { _env.Warning($"! {ex.Message} for '{req}'. {endpoint} DOWN"); _outages[i] = now + _downtime; } } } // we've exhausted all gateways. throw new IOException("No gateways active"); }
public static Task <IConn> Connect(this IEnv env, string server, ushort port) { return(env.Connect(new SimEndpoint(server, port))); }