private Task PassTtl(string serviceId) { _logger?.LogDebug("Sending consul heartbeat for: {serviceId} ", serviceId); try { SendHeartbeatRequest sendHeartbeatRequest = new SendHeartbeatRequest() { Ephemeral = false, ServiceName = Options.ServiceName, GroupName = Options.GroupName, BeatInfo = new BeatInfo { Ip = Options.Host, Port = Options.Port, ServiceName = Options.ServiceName, Scheduled = true, Cluster = Options.ClusterName, }, }; return(_client.SendHeartbeatAsync(sendHeartbeatRequest)); } catch (Exception e) { _logger?.LogError(e, "Exception sending consul heartbeat for: {serviceId} ", serviceId); } return(Task.CompletedTask); }
public Task StartAsync(CancellationToken cancellationToken) { uris = UriTool.GetUri(_features, _options); foreach (var uri in uris) { _logger.LogInformation("Report instance ({0}:{1}) status....", uri.Host, uri.Port); var metadata = new Dictionary <string, string>() { { PreservedMetadataKeys.REGISTER_SOURCE, "ASPNET_CORE" } }; foreach (var item in _options.Metadata) { if (!metadata.ContainsKey(item.Key)) { metadata.TryAdd(item.Key, item.Value); } } var beatRequest = new SendHeartbeatRequest { Ephemeral = true, ServiceName = _options.ServiceName, GroupName = _options.GroupName, BeatInfo = new BeatInfo { ip = uri.Host, port = uri.Port, serviceName = _options.ServiceName, scheduled = true, weight = _options.Weight, cluster = _options.ClusterName, metadata = metadata, }, NameSpaceId = _options.Namespace }; beatRequests.Add(beatRequest); } _timer = new Timer( async x => { if (_reporting) { _logger.LogInformation($"Latest manipulation is still working ..."); return; } _reporting = true; await ReportAsync(); _reporting = false; }, null, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(10)); return(Task.CompletedTask); }
/// <summary> /// Use to get the current status of devices registered on SageMaker Edge Manager. /// </summary> /// <param name="request">Container for the necessary parameters to execute the SendHeartbeat service method.</param> /// <param name="cancellationToken"> /// A cancellation token that can be used by other objects or threads to receive notice of cancellation. /// </param> /// /// <returns>The response from the SendHeartbeat service method, as returned by SagemakerEdgeManager.</returns> /// <exception cref="Amazon.SagemakerEdgeManager.Model.InternalServiceException"> /// An internal failure occurred. Try your request again. If the problem persists, contact /// AWS customer support. /// </exception> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/sagemaker-edge-2020-09-23/SendHeartbeat">REST API Reference for SendHeartbeat Operation</seealso> public virtual Task <SendHeartbeatResponse> SendHeartbeatAsync(SendHeartbeatRequest request, System.Threading.CancellationToken cancellationToken = default(CancellationToken)) { var options = new InvokeOptions(); options.RequestMarshaller = SendHeartbeatRequestMarshaller.Instance; options.ResponseUnmarshaller = SendHeartbeatResponseUnmarshaller.Instance; return(InvokeAsync <SendHeartbeatResponse>(request, options, cancellationToken)); }
internal virtual SendHeartbeatResponse SendHeartbeat(SendHeartbeatRequest request) { var options = new InvokeOptions(); options.RequestMarshaller = SendHeartbeatRequestMarshaller.Instance; options.ResponseUnmarshaller = SendHeartbeatResponseUnmarshaller.Instance; return(Invoke <SendHeartbeatResponse>(request, options)); }
/// <summary> /// Initiates the asynchronous execution of the SendHeartbeat operation. /// </summary> /// /// <param name="request">Container for the necessary parameters to execute the SendHeartbeat operation on AmazonSagemakerEdgeManagerClient.</param> /// <param name="callback">An AsyncCallback delegate that is invoked when the operation completes.</param> /// <param name="state">A user-defined state object that is passed to the callback procedure. Retrieve this object from within the callback /// procedure using the AsyncState property.</param> /// /// <returns>An IAsyncResult that can be used to poll or wait for results, or both; this value is also needed when invoking EndSendHeartbeat /// operation.</returns> /// <seealso href="http://docs.aws.amazon.com/goto/WebAPI/sagemaker-edge-2020-09-23/SendHeartbeat">REST API Reference for SendHeartbeat Operation</seealso> public virtual IAsyncResult BeginSendHeartbeat(SendHeartbeatRequest request, AsyncCallback callback, object state) { var options = new InvokeOptions(); options.RequestMarshaller = SendHeartbeatRequestMarshaller.Instance; options.ResponseUnmarshaller = SendHeartbeatResponseUnmarshaller.Instance; return(BeginInvoke(request, options, callback, state)); }
public async Task SendHeartbeat_Should_Succeed() { var request = new SendHeartbeatRequest { ServiceName = "testservice", BeatInfo = new BeatInfo { serviceName = "testservice", ip = "192.168.0.74", port = 9999, } }; var res = await _namingClient.SendHeartbeatAsync(request); Assert.True(res); }