Skip to content

Commit 9063c01

Browse files
committed
misc
- renamed is_iis env var - added timestamps to start config, helps to diagnose slow starts - cleaned out unused types
1 parent 840199e commit 9063c01

File tree

7 files changed

+32
-37
lines changed

7 files changed

+32
-37
lines changed

src/Tetrifact.Core/DateTimeSpanExtensions.cs

+11-3
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ private static string _agoLocalTime(DateTime beforeUtc, bool shorten = false)
8080

8181
private static string _ago(TimeSpan ts, bool shorten)
8282
{
83-
int count = 0;
83+
int count;
8484
string unit = string.Empty;
8585
string pluralMod = string.Empty;
8686
if (ts.TotalDays > 364)
@@ -113,10 +113,18 @@ private static string _ago(TimeSpan ts, bool shorten)
113113
unit = shorten ? "m" : "minute";
114114
pluralMod = shorten ? string.Empty : "s";
115115
return $"{count} {unit}" + (count == 1 ? "" : pluralMod);
116+
}
117+
118+
if (ts.TotalMilliseconds >= 1000)
119+
{
120+
count = (int)Math.Round(ts.TotalSeconds, 0);
121+
unit = shorten ? "s" : "second";
122+
pluralMod = shorten ? string.Empty : "s";
123+
return $"{count} {unit}" + (count == 1 ? "" : pluralMod);
116124
}
117125

118-
count = (int)Math.Round(ts.TotalSeconds, 0);
119-
unit = shorten ? "s" : "second";
126+
count = (int)Math.Round(ts.TotalMilliseconds, 0);
127+
unit = shorten ? "ms" : "millisecond";
120128
pluralMod = shorten ? string.Empty : "s";
121129
return $"{count} {unit}" + (count == 1 ? "" : pluralMod);
122130
}

src/Tetrifact.Core/GlobalFlags.cs

-23
This file was deleted.

src/Tetrifact.Web/Core/Globals.cs

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
using System;
2+
3+
namespace Tetrifact.Core
4+
{
5+
public class Global
6+
{
7+
public static DateTime StartTimeUtc { get; private set; } = DateTime.UtcNow;
8+
}
9+
}

src/Tetrifact.Web/Program.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ public class Program
1313
public static void Main(string[] args)
1414
{
1515
Console.WriteLine("*********************************************************************");
16-
Console.WriteLine("TETRIFACT : server starting");
16+
Console.WriteLine("TETRIFACT server starting");
1717
Console.WriteLine("");
18+
1819
CreateWebHostBuilder(args).Build().Run();
1920
}
2021

@@ -34,7 +35,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args)
3435
})
3536
.UseStartup<Startup>();
3637

37-
bool isIIS = Environment.GetEnvironmentVariable("IS_IIS") == "true";
38+
bool use_IIS = Environment.GetEnvironmentVariable("TETRIFACT_USE_IIS") == "true";
3839
bool useHTTPS = EnvironmentArgsHelper.GetAsBool("TETRIFACT_USE_HTTPS");
3940
string httpsCertPath = Environment.GetEnvironmentVariable("TETRIFACT_HTTPS_CERT_PATH");
4041
int port = EnvironmentArgsHelper.GetAsInt("TETRIFACT_PORT", 5000);
@@ -44,7 +45,7 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args)
4445
useHTTPS = false;
4546
}
4647

47-
if (!isIIS)
48+
if (!use_IIS)
4849
{
4950
builder.UseKestrel(options =>
5051
{
@@ -55,14 +56,15 @@ public static IWebHostBuilder CreateWebHostBuilder(string[] args)
5556
if (useHTTPS)
5657
listenOptions.UseHttps(httpsCertPath);
5758
});
58-
Console.WriteLine("Port bound.");
59+
Console.WriteLine($"Port bound ({Global.StartTimeUtc.Ago(true)})");
5960

6061
// SECURITY WARNING : the limit on attachment part size is removed to support large builds.
6162
options.Limits.MaxRequestBodySize = long.MaxValue;
6263
options.Limits.MaxRequestBufferSize = long.MaxValue;
6364
options.Limits.MaxRequestLineSize = int.MaxValue;
6465
});
65-
Console.WriteLine("Kestrel loaded.");
66+
67+
Console.WriteLine($"Kestrel loaded ({Global.StartTimeUtc.Ago(true)})");
6668
}
6769

6870
return builder;

src/Tetrifact.Web/Properties/launchSettings.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"STORAGE_COMPRESSION": "False",
2424
"ASPNETCORE_ENVIRONMENT": "Development",
2525
"AUTO_CREATE_ARCHIVE_ON_PACKAGE_CREATE": "True",
26-
"IS_IIS": "true"
26+
"TETRIFACT_USE_IIS": "true"
2727
}
2828
},
2929
"src": {

src/Tetrifact.Web/Startup.cs

+3-4
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
using System.IO.Abstractions;
1313
using Tetrifact.Core;
1414
using Microsoft.AspNetCore.Server.Kestrel.Core;
15-
using Microsoft.Extensions.Hosting.Internal;
1615

1716
namespace Tetrifact.Web
1817
{
@@ -31,7 +30,7 @@ public Startup(IConfiguration configuration)
3130
/// <param name="services"></param>
3231
public void ConfigureServices(IServiceCollection services)
3332
{
34-
Console.WriteLine("Configuring services");
33+
Console.WriteLine($"Configuring services ({Global.StartTimeUtc.Ago(true)})");
3534

3635
services.Configure<CookiePolicyOptions>(options =>
3736
{
@@ -152,7 +151,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
152151
}
153152
});
154153

155-
Console.WriteLine("Configuring middleware.");
154+
Console.WriteLine($"Configuring middleware ({Global.StartTimeUtc.Ago(true)})");
156155

157156

158157
app.UseHttpsRedirection();
@@ -213,7 +212,7 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env, ILoggerF
213212
foreach (ICron cron in crons)
214213
cron.Start();
215214

216-
Console.WriteLine("Server start complete.");
215+
Console.WriteLine($"Server configuration complete ({Global.StartTimeUtc.Ago(true)})");
217216
Console.WriteLine("*********************************************************************");
218217
}
219218
}

src/Tetrifact.Web/web.config

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" hostingModel="InProcess">
88
<environmentVariables>
99
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development" />
10-
<environmentVariable name="IS_IIS" value="true" />
10+
<environmentVariable name="TETRIFACT_USE_IIS" value="true" />
1111
<environmentVariable name="LIST_PAGE_SIZE" value="10" />
1212
<environmentVariable name="AUTH_LEVEL" value="Write" />
1313
<environmentVariable name="ACCESS_TOKENS" value="" />

0 commit comments

Comments
 (0)