Skip to content

Commit

Permalink
Add some stuff
Browse files Browse the repository at this point in the history
- Fixed bug where healthchecks url would not work
- Added sentry support
- Added docker compose configuration
  • Loading branch information
smallketchup82 committed Aug 25, 2024
1 parent 12cfc57 commit 5891e43
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 3 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -529,3 +529,4 @@ Network Trash Folder
Temporary Items
.apdisk

.env
11 changes: 11 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
services:
ketchupbot-updater:
image: ketchupbot-updater
restart: unless-stopped
command: --turrets -ss "0 0 * ? * * *"
env_file:
- .env
build:
context: .
dockerfile: ketchupbot-updater/Dockerfile

42 changes: 42 additions & 0 deletions ketchupbot-framework/API/HealthChecks.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,46 @@ public static async Task Ping(string url)
Log.Error(e, "Failed to ping {Url}", url);
}
}

public static async Task BroadcastInProgress(string url)
{
try
{
HttpResponseMessage response = await Client.GetAsync(url + "?status=in_progress");
response.EnsureSuccessStatusCode();
Log.Information("Broadcasted in progress to {Url}", url);;
}
catch (HttpRequestException e)
{
Log.Error(e, "Failed to broadcast in progress to {Url}", url);
}
}

public static async Task BroadcastComplete(string url)
{
try
{
HttpResponseMessage response = await Client.GetAsync(url + "?status=ok");
response.EnsureSuccessStatusCode();
Log.Information("Broadcasted complete to {Url}", url);
}
catch (HttpRequestException e)
{
Log.Error(e, "Failed to broadcast completed to {Url}", url);
}
}

public static async Task BroadcastFailure(string url)
{
try
{
HttpResponseMessage response = await Client.GetAsync(url + "?status=error");
response.EnsureSuccessStatusCode();
Log.Information("Broadcasted failure to {Url}", url);
}
catch (HttpRequestException e)
{
Log.Error(e, "Failed to broadcast failed to {Url}", url);
}
}
}
5 changes: 5 additions & 0 deletions ketchupbot-updater.sln
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ketchupbot-updater-tests",
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ketchupbot-framework", "ketchupbot-framework\ketchupbot-framework.csproj", "{CEA415C6-6CA0-4117-9962-CFEB79371AD8}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{5B671AED-2C58-4C95-B11D-0652A62DF4B6}"
ProjectSection(SolutionItems) = preProject
docker-compose.yml = docker-compose.yml
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down
4 changes: 3 additions & 1 deletion ketchupbot-updater/Jobs/MassUpdateJob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ public async Task Execute(IJobExecutionContext context)
string? healthChecksUrl = jobDataMap.TryGetString("healthChecksUrl", out string? healthChecksUrlRaw) ? healthChecksUrlRaw : null;
if (shipUpdater == null) throw new InvalidOperationException("ShipUpdater not found in job data map");

if (healthChecksUrl != null) await HealthChecks.BroadcastInProgress(healthChecksUrl);

// I was thinking that maybe we should wrap this in a try/catch block. And we probably should, because I don't
// think we'd be able to catch any errors further up in the call stack. Not sure though, so I'll leave it for
// now until I make a decision.
await shipUpdater.UpdateAllShips();

if (healthChecksUrl != null) await HealthChecks.Ping(healthChecksUrl);
if (healthChecksUrl != null) await HealthChecks.BroadcastComplete(healthChecksUrl);

Console.WriteLine("Mass update job completed");
if (context.NextFireTimeUtc != null)
Expand Down
16 changes: 14 additions & 2 deletions ketchupbot-updater/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ private static async Task<int> Main(string[] args)

#endregion

SentrySdk.Init(options =>
{
options.Dsn = configuration["SENTRY_DSN"];
options.AutoSessionTracking = true;
options.TracesSampleRate = 1.0;
options.ProfilesSampleRate = 1.0;

#if DEBUG
options.Debug = true;
#endif
});

var mwClient = new MwClient(configuration["MWUSERNAME"] ?? throw new InvalidOperationException("MWUSERNAME not set"),
configuration["MWPASSWORD"] ?? throw new InvalidOperationException("MWPASSWORD not set"));
Log.Information("Logged into the Galaxypedia");
Expand Down Expand Up @@ -162,7 +174,7 @@ private static async Task<int> Main(string[] args)
.Build();

massUpdateJob.JobDataMap.Put("shipUpdater", shipUpdater);
massUpdateJob.JobDataMap.Put("healthCheckUrl", configuration["HEALTHCHECK_URL"]);
massUpdateJob.JobDataMap.Put("healthChecksUrl", configuration["HEALTHCHECK_URL"]);

ITrigger massUpdateTrigger = TriggerBuilder.Create()
.WithIdentity("massUpdateTrigger", "group1")
Expand All @@ -173,7 +185,7 @@ private static async Task<int> Main(string[] args)

await scheduler.ScheduleJob(massUpdateJob, massUpdateTrigger);
Console.WriteLine($"Scheduled ship mass update job for {massUpdateTrigger.GetNextFireTimeUtc()?.ToLocalTime()}");
Console.WriteLine("Running mass update job now...");
Console.WriteLine("Running a mass update job now...");
await scheduler.TriggerJob(new JobKey("massUpdateJob", "group1"));
}

Expand Down
1 change: 1 addition & 0 deletions ketchupbot-updater/ketchupbot-updater.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This project is a standalone application that builds upon ketchupbot-framework t
<PackageReference Include="Microsoft.Extensions.Configuration.Json" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Configuration.UserSecrets" Version="8.0.0" />
<PackageReference Include="Quartz" Version="3.12.0" />
<PackageReference Include="Sentry" Version="4.10.2" />
<PackageReference Include="Serilog" Version="4.0.1" />
<PackageReference Include="Serilog.Enrichers.Thread" Version="4.0.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
Expand Down

0 comments on commit 5891e43

Please sign in to comment.