Skip to content

Commit fd590cc

Browse files
Adjust shutdown (#2)
* Update PrometheusMetrics.cs * Update PatchClass.cs * Update ACE_NET_runtime_metrics_dashboard.json * Update PatchClass.cs * Update PrometheusMetrics.cs * Update BeforeBuild.ps1 * Update BeforeBuild.ps1 * Update BeforeBuild.ps1 * Update BeforeBuild.ps1
1 parent 86ba60e commit fd590cc

File tree

4 files changed

+260
-101
lines changed

4 files changed

+260
-101
lines changed

ACE.Mods.Metrics/PatchClass.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,13 +33,13 @@ public override Task OnStartSuccess()
3333
// return Task.CompletedTask;
3434
//}
3535

36-
protected override void SettingsChanged(object sender, EventArgs e)
37-
{
38-
StopServices();
39-
base.SettingsChanged(sender, e);
40-
Settings = SettingsContainer?.Settings ?? new();
41-
StartServices();
42-
}
36+
//protected override void SettingsChanged(object sender, EventArgs e)
37+
//{
38+
// StopServices();
39+
// base.SettingsChanged(sender, e);
40+
// Settings = SettingsContainer?.Settings ?? new();
41+
// StartServices();
42+
//}
4343

4444
public override void Stop()
4545
{
@@ -53,7 +53,7 @@ public static void StartServices()
5353
{
5454
PrometheusMetrics.InitMetrics();
5555

56-
Mod.Log($"Metrics Exporter Online and listening to requests at http{(Settings.UseHTTPs ? "s" : "")}://{Settings.Host}:{Settings.Port}" + "/" + $"{Settings.Url}");
56+
Mod.Log($"Metrics Exporter Online and listening to requests at:\n http{(Settings.UseHTTPs ? "s" : "")}://{Settings.Host}:{Settings.Port}" + "/" + $"{Settings.Url}");
5757
}
5858
catch (Exception ex)
5959
{

ACE.Mods.Metrics/PrometheusMetrics.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,15 @@ public static void InitMetrics()
141141

142142
public static void ShutdownMetrics()
143143
{
144-
// todo this throws exception
145-
//dotNetMetricsCollector.Dispose();
144+
dotNetMetricsCollector?.Dispose();
145+
146+
dotNetMetricsCollector = null;
146147

147148
metricServer?.Stop();
149+
150+
metricServer?.Dispose();
151+
152+
metricServer = null;
148153
}
149154

150155
static void MetricsAddBeforeCollectCallback()

AppVeyor/BeforeBuild.ps1

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,25 @@ function Format-Json
33
<#
44
.SYNOPSIS
55
Applies proper formatting to a JSON string with the specified indentation.
6-
6+
77
.DESCRIPTION
8-
The `Format-Json` function takes a JSON string as input and formats it with the specified level of indentation.
8+
The `Format-Json` function takes a JSON string as input and formats it with the specified level of indentation.
99
The function processes each line of the JSON string, adjusting the indentation level based on the structure of the JSON.
10-
10+
1111
.PARAMETER Json
1212
The JSON string to be formatted.
1313
This parameter is mandatory and accepts input from the pipeline.
14-
14+
1515
.PARAMETER Indentation
1616
Specifies the number of spaces to use for each indentation level.
17-
The value must be between 1 and 1024.
17+
The value must be between 1 and 1024.
1818
The default value is 2.
19-
19+
2020
.EXAMPLE
2121
$formattedJson = Get-Content -Path 'config.json' | Format-Json -Indentation 4
22-
This example reads the JSON content from a file named 'config.json', formats it with an
22+
This example reads the JSON content from a file named 'config.json', formats it with an
2323
indentation level of 4 spaces, and stores the result in the `$formattedJson` variable.
24-
24+
2525
.EXAMPLE
2626
@'
2727
{
@@ -33,40 +33,40 @@ function Format-Json
3333
}
3434
'@ | Format-Json
3535
This example formats an inline JSON string with the default indentation level of 2 spaces.
36-
36+
3737
.NOTES
3838
This function assumes that the input string is valid JSON.
3939
#>
4040
param
4141
(
4242
[Parameter(Mandatory = $true, ValueFromPipeline = $true)]
4343
[String]$Json,
44-
44+
4545
[ValidateRange(1, 1024)]
4646
[Int]$Indentation = 2
4747
)
48-
48+
4949
$lines = $Json -split '\n'
50-
50+
5151
$indentLevel = 0
52-
52+
5353
$result = $lines | ForEach-Object `
5454
{
5555
if ($_ -match "[\}\]]")
5656
{
5757
$indentLevel--
5858
}
59-
59+
6060
$line = (' ' * $indentLevel * $Indentation) + $_.TrimStart().Replace(": ", ": ")
61-
61+
6262
if ($_ -match "[\{\[]")
6363
{
6464
$indentLevel++
6565
}
66-
66+
6767
return $line
6868
}
69-
69+
7070
return $result -join "`n"
7171
}
7272

@@ -79,7 +79,12 @@ try {
7979
$jsonData = Get-Content $jsonFilePath -Raw | ConvertFrom-Json
8080
$jsonData.Version = "$Env:APPVEYOR_BUILD_VERSION"
8181

82-
$jsonData | ConvertTo-Json | Format-Json | Out-File $jsonFilePath
82+
#$jsonData | ConvertTo-Json | Format-Json | Out-File $jsonFilePath -Encoding UTF8
83+
84+
$utf8NoBomEncoding = New-Object System.Text.UTF8Encoding $false
85+
$jsonContent = $jsonData | ConvertTo-Json | Format-Json
86+
$jsonFilePath2 = [System.Environment]::GetEnvironmentVariable('APPVEYOR_BUILD_FOLDER') + "\" + [System.Environment]::GetEnvironmentVariable('APPVEYOR_PROJECT_NAME') + "\Meta.json"
87+
[System.IO.File]::WriteAllText($jsonFilePath2, $jsonContent, $utf8NoBomEncoding)
8388

8489
Write-Host "OK" -ForegroundColor Green
8590

0 commit comments

Comments
 (0)