Skip to content

Commit 70840a4

Browse files
Add logic to rebuild if the next upcoming event has ended
1 parent a880d0a commit 70840a4

File tree

3 files changed

+88
-16
lines changed

3 files changed

+88
-16
lines changed

.github/workflows/scheduler.yml

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,53 @@ jobs:
1111
name: Check for content updates
1212
runs-on: ubuntu-latest
1313
outputs:
14-
has-updates: ${{ steps.check-commit.outputs.has-updates }}
15-
new-commit: ${{ steps.check-commit.outputs.new-commit }}
14+
has-updates: ${{ steps.check-updates.outputs.has-updates }}
15+
new-commit: ${{ steps.check-updates.outputs.new-commit }}
1616

1717
steps:
1818
- name: Checkout
1919
uses: actions/checkout@v4
2020

21-
- name: Check for new upstream commit
22-
id: check-commit
21+
- name: Check for new upstream commit or event end
22+
id: check-updates
2323
run: |
2424
UPSTREAM_REPO="owddm/public"
2525
2626
# Read current commit from meta.json
2727
CURRENT_COMMIT=$(jq -r '.commitHash' content/meta.json)
2828
echo "Current commit: $CURRENT_COMMIT"
2929
30+
# Read nextEventEnds from meta.json
31+
NEXT_EVENT_ENDS=$(jq -r '.nextEventEnds' content/meta.json)
32+
echo "Next event ends: $NEXT_EVENT_ENDS"
3033
3134
# Get latest commit from upstream main branch
3235
LATEST_COMMIT=$(curl -s "https://api.github.com/repos/$UPSTREAM_REPO/commits/main" | jq -r '.sha')
3336
echo "Latest upstream commit: $LATEST_COMMIT"
3437
38+
# Check if we need to trigger a build
39+
NEEDS_BUILD=false
40+
41+
# Check for new commit
3542
if [ "$CURRENT_COMMIT" != "$LATEST_COMMIT" ]; then
3643
echo "New commit detected!"
37-
echo "has-updates=true" >> $GITHUB_OUTPUT
44+
NEEDS_BUILD=true
3845
echo "new-commit=$LATEST_COMMIT" >> $GITHUB_OUTPUT
46+
fi
47+
48+
# Check if an event has ended and we need to rebuild
49+
if [ "$NEXT_EVENT_ENDS" != "null" ] && [ "$NEXT_EVENT_ENDS" != "" ]; then
50+
CURRENT_TIME=$(date -u +"%Y-%m-%dT%H:%M:%S.000Z")
51+
if [[ "$CURRENT_TIME" > "$NEXT_EVENT_ENDS" ]]; then
52+
echo "Event has ended, triggering rebuild to update event status"
53+
NEEDS_BUILD=true
54+
fi
55+
fi
56+
57+
if [ "$NEEDS_BUILD" = true ]; then
58+
echo "has-updates=true" >> $GITHUB_OUTPUT
3959
else
40-
echo "No new commits"
60+
echo "No updates needed"
4161
echo "has-updates=false" >> $GITHUB_OUTPUT
4262
fi
4363

scripts/import-data/lib/import.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import fs from "node:fs/promises";
22
import path from "node:path";
33

4+
import { filterUpcomingEvents, getEventEndTimeWithBuffer } from "@/utils/eventFilters";
5+
46
import { CONTENT_DIR, getGithubRawUrl } from "./constants";
57
import { processEvent } from "./events";
68
import { githubFetchJSON } from "./github-fetch";
@@ -197,10 +199,52 @@ export async function handleImport(args: string[]) {
197199

198200
// Create meta.json
199201
logger.section("Creating Metadata");
202+
203+
// Calculate nextEventEnds - the end time of the next upcoming event
204+
let nextEventEnds: string | null = null;
205+
206+
// Convert events to match the EventWithDateTime interface
207+
const allEvents = [];
208+
for (const [, groupData] of Object.entries(eventsWithVenuesJSON.groups)) {
209+
for (const event of groupData.events) {
210+
allEvents.push({
211+
data: {
212+
dateTime: new Date(event.time),
213+
duration: event.duration ? Math.round(event.duration / 60000) : undefined,
214+
},
215+
// Keep additional properties for logging
216+
title: event.title,
217+
id: event.id,
218+
});
219+
}
220+
}
221+
222+
// Get upcoming events using the existing filter
223+
const upcomingEvents = filterUpcomingEvents(allEvents);
224+
225+
if (upcomingEvents.length > 0) {
226+
// Sort by end time to get the event that will end soonest
227+
upcomingEvents.sort((a, b) => {
228+
const aEndTime = getEventEndTimeWithBuffer(a).getTime();
229+
const bEndTime = getEventEndTimeWithBuffer(b).getTime();
230+
return aEndTime - bEndTime;
231+
});
232+
233+
// Get the event that will end soonest
234+
const nextEventToEnd = upcomingEvents[0];
235+
const endTime = getEventEndTimeWithBuffer(nextEventToEnd);
236+
nextEventEnds = endTime.toISOString();
237+
238+
logger.info(`Next event ends: ${nextEventEnds} (Event: "${nextEventToEnd.title}")`);
239+
} else {
240+
logger.info("No upcoming events found");
241+
}
242+
200243
const metaData = {
201244
commitDate: commitInfo.date,
202245
commitHash: commitInfo.sha,
203246
repository: "https://github.com/owddm/public",
247+
nextEventEnds,
204248
};
205249

206250
const metaPath = path.join(CONTENT_DIR, "meta.json");

src/utils/eventFilters.ts

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,18 @@ import type { EventEnriched } from "@/content";
33
// an event is considered "ended" if it has ended + 30 min buffer
44
const BUFFER_MINUTES = 30;
55

6+
// Minimal event data interface that can be satisfied by both EventEnriched and import data
7+
interface EventWithDateTime {
8+
data: {
9+
dateTime: Date;
10+
duration?: number;
11+
};
12+
}
13+
614
/**
715
* Calculates the end time of an event including a buffer period
816
*/
9-
export function getEventEndTimeWithBuffer(event: EventEnriched): Date {
17+
export function getEventEndTimeWithBuffer(event: EventWithDateTime): Date {
1018
const startTime = new Date(event.data.dateTime);
1119
const durationMinutes = event.data.duration || 120; // Default 2 hours if not specified
1220
const totalMinutes = durationMinutes + BUFFER_MINUTES;
@@ -18,7 +26,7 @@ export function getEventEndTimeWithBuffer(event: EventEnriched): Date {
1826
* Checks if an event should be shown as upcoming
1927
* Events are considered upcoming if they haven't ended (including 30 min buffer)
2028
*/
21-
export function isEventUpcoming(event: EventEnriched, currentTime: Date = new Date()): boolean {
29+
export function isEventUpcoming(event: EventWithDateTime, currentTime: Date = new Date()): boolean {
2230
const endTimeWithBuffer = getEventEndTimeWithBuffer(event);
2331
return endTimeWithBuffer > currentTime;
2432
}
@@ -27,35 +35,35 @@ export function isEventUpcoming(event: EventEnriched, currentTime: Date = new Da
2735
* Checks if an event should be shown as recent
2836
* Events are considered recent if they have ended (including 30 min buffer)
2937
*/
30-
export function isEventRecent(event: EventEnriched, currentTime: Date = new Date()): boolean {
38+
export function isEventRecent(event: EventWithDateTime, currentTime: Date = new Date()): boolean {
3139
const endTimeWithBuffer = getEventEndTimeWithBuffer(event);
3240
return endTimeWithBuffer <= currentTime;
3341
}
3442

3543
/**
3644
* Filters events to get upcoming ones (haven't ended + 30 min buffer)
3745
*/
38-
export function filterUpcomingEvents(
39-
events: EventEnriched[],
46+
export function filterUpcomingEvents<T extends EventWithDateTime>(
47+
events: T[],
4048
currentTime: Date = new Date(),
41-
): EventEnriched[] {
49+
): T[] {
4250
return events.filter((event) => isEventUpcoming(event, currentTime));
4351
}
4452

4553
/**
4654
* Filters events to get recent ones (have ended + 30 min buffer)
4755
*/
48-
export function filterRecentEvents(
49-
events: EventEnriched[],
56+
export function filterRecentEvents<T extends EventWithDateTime>(
57+
events: T[],
5058
currentTime: Date = new Date(),
51-
): EventEnriched[] {
59+
): T[] {
5260
return events.filter((event) => isEventRecent(event, currentTime));
5361
}
5462

5563
/**
5664
* Checks if an event is a legacy event (2025.10.10 or earlier)
5765
*/
58-
export function isLegacyEvent(event: EventEnriched): boolean {
66+
export function isLegacyEvent(event: EventWithDateTime | EventEnriched): boolean {
5967
const eventDate = new Date(event.data.dateTime);
6068
const legacyCutoff = new Date("2025-10-10T23:59:59");
6169
return eventDate <= legacyCutoff;

0 commit comments

Comments
 (0)