Skip to content

Commit 71a427e

Browse files
Copilotcsharpfritz
andcommitted
Implement Content folder workflow optimization
Co-authored-by: csharpfritz <[email protected]>
1 parent bd1322f commit 71a427e

5 files changed

Lines changed: 63 additions & 1 deletion

File tree

.github/workflows/azure-dev.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
name: Build and Deploy
22

3-
# Run when commits are pushed to main
3+
# Run when commits are pushed to main (excluding Content folder changes)
44
on:
55
workflow_dispatch:
66
push:
77
# Run when commits are pushed to mainline branch (main or master)
88
# Set this to the mainline branch you are using
99
branches:
1010
- main
11+
# Exclude Content folder changes to avoid unnecessary deployments
12+
paths-ignore:
13+
- 'Content/**'
1114

1215
# Set up permissions for deploying with secretless Azure federated credentials
1316
# https://learn.microsoft.com/en-us/azure/developer/github/connect-from-azure?tabs=azure-portal%2Clinux#set-up-azure-login-with-openid-connect-authentication

.github/workflows/content-sync.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,26 @@ jobs:
3636
AZURE_STORAGE_CONNECTION_STRING: ${{ secrets.CONTENT_STORAGE_CONNECTION_STRING }}
3737
run: dotnet run --project ContentLoader/ContentLoader.csproj --configuration Release -- Content
3838

39+
- name: Refresh Web App Cache
40+
if: success()
41+
run: |
42+
echo "Refreshing web application cache..."
43+
# Wait a moment for the content to be fully uploaded
44+
sleep 5
45+
46+
# Call the cache refresh endpoint
47+
response=$(curl -s -w "%{http_code}" -X POST "https://copilotthatjawn.com/api/cache/refresh" -o /tmp/cache_response.json)
48+
49+
if [ "$response" = "200" ]; then
50+
echo "Cache refresh successful"
51+
cat /tmp/cache_response.json
52+
else
53+
echo "Cache refresh failed with HTTP status: $response"
54+
cat /tmp/cache_response.json || echo "No response body"
55+
# Don't fail the workflow if cache refresh fails - it's not critical
56+
echo "Continuing workflow despite cache refresh failure..."
57+
fi
58+
3959
- name: Handle Failure
4060
if: failure()
4161
run: |

Web/Extensions/EndpointExtensions.cs

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,4 +192,40 @@ public static class EndpointExtensions
192192
.SetVaryByHost(true)
193193
.Tag("rss"));
194194
}
195+
196+
public static void MapCacheRefreshEndpoint(this WebApplication app)
197+
{
198+
app.MapPost("/api/cache/refresh", async (IContentService contentService, ILogger<Program> logger, IWebHostEnvironment environment) =>
199+
{
200+
try
201+
{
202+
logger.LogInformation("Cache refresh requested via API endpoint");
203+
204+
// Only perform cache refresh in non-development environments
205+
// In development, the cache isn't as critical and may require Azure Table Storage
206+
if (environment.IsDevelopment())
207+
{
208+
logger.LogInformation("Development environment detected. Skipping cache refresh.");
209+
return Results.Ok(new {
210+
message = "Cache refresh skipped in development environment",
211+
timestamp = DateTime.UtcNow,
212+
environment = "Development"
213+
});
214+
}
215+
216+
await contentService.RefreshContentAsync();
217+
218+
logger.LogInformation("Cache refresh completed successfully");
219+
return Results.Ok(new { message = "Cache refreshed successfully", timestamp = DateTime.UtcNow });
220+
}
221+
catch (Exception ex)
222+
{
223+
logger.LogError(ex, "Error refreshing cache via API endpoint");
224+
return Results.Problem("Failed to refresh cache", statusCode: 500);
225+
}
226+
})
227+
.WithName("RefreshCache")
228+
.WithSummary("Refresh the content cache")
229+
.WithDescription("Triggers a refresh of the in-memory content cache from Azure Table Storage");
230+
}
195231
}

Web/Program.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@
156156
app.MapSitemapEndpoint();
157157
app.MapRssFeedEndpoint();
158158

159+
// Map cache refresh endpoint
160+
app.MapCacheRefreshEndpoint();
161+
159162
app.MapDefaultEndpoints();
160163

161164
app.Run();

packages-microsoft-prod.deb

-3.61 KB
Binary file not shown.

0 commit comments

Comments
 (0)