Skip to content

Commit

Permalink
fix: remove ServiceDiscoveryIPv4 caching
Browse files Browse the repository at this point in the history
  • Loading branch information
romanov.ah committed Aug 22, 2024
1 parent e10e926 commit 2a4f324
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions Vostok.Commons.Environment/EnvironmentInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Net.Sockets;
using System.Reflection;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using JetBrains.Annotations;

namespace Vostok.Commons.Environment
Expand All @@ -25,12 +24,11 @@ internal static class EnvironmentInfo
private static Lazy<string> application = new Lazy<string>(ObtainApplicationName);
private static Lazy<string> host = new Lazy<string>(ObtainHostname);
private static Lazy<string> fqdn = new Lazy<string>(ObtainFQDN);
private static Lazy<string> serviceDiscoveryIPv4 = new Lazy<string>(ObtainServiceDiscoveryIPv4);
private static Lazy<string> processName = new Lazy<string>(GetProcessNameOrNull);
private static Lazy<string> homeDirectory = new Lazy<string>(ObtainHomeDirectory);
private static Lazy<int?> processId = new Lazy<int?>(GetProcessIdOrNull);

private static readonly TimeSpan CacheTtl = TimeSpan.FromSeconds(3);

/// <summary>
/// Returns the name of the application.
/// </summary>
Expand All @@ -47,9 +45,9 @@ internal static class EnvironmentInfo
public static string FQDN => fqdn.Value;

/// <summary>
/// Returns the IPv4 of the machine running the application.
/// Returns the IPv4 through which the application is accessible on the hosting network.
/// </summary>
public static volatile string ServiceDiscoveryIPv4;
public static string ServiceDiscoveryIPv4 => serviceDiscoveryIPv4.Value;

/// <summary>
/// Returns the name of current process.
Expand All @@ -71,18 +69,6 @@ internal static class EnvironmentInfo
/// </summary>
public static string HomeDirectory => homeDirectory.Value;

static EnvironmentInfo()
{
UpdateAndSchedule();
}

private static void UpdateAndSchedule()
{
ServiceDiscoveryIPv4 = ObtainServiceDiscoveryIPv4();

Task.Delay(CacheTtl).ContinueWith(_ => UpdateAndSchedule());
}

private static string ObtainApplicationName()
{
try
Expand Down

0 comments on commit 2a4f324

Please sign in to comment.