File tree Expand file tree Collapse file tree
packages/shared/src/utils/redis Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11/// <reference types="next" />
22/// <reference types="next/image-types/global" />
3- import './.next/types/routes.d.ts'
3+ import './.next/dev/ types/routes.d.ts'
44
55// NOTE: This file should not be edited
66// see https://nextjs.org/docs/app/api-reference/config/typescript for more information.
Original file line number Diff line number Diff line change 22 * Static constant configuration values
33 */
44
5- import { remove } from 'winston'
6-
75export const config = {
86 // The number of worker threads to spawn for processing background jobs
97 workerThreadCount : 5 ,
Original file line number Diff line number Diff line change 1+ export async function revalidateWebsitePage (
2+ paths : string [ ] = [ ] ,
3+ tags : string [ ] = [ ] ,
4+ ) : Promise < { revalidated : boolean } > {
5+ try {
6+ const res = await fetch ( process . env . FRONTEND_URL + '/api/revalidate' , {
7+ method : 'POST' ,
8+ headers : {
9+ 'Content-Type' : 'application/json' ,
10+ 'User-Agent' : 'BuildTheEarth Worker' ,
11+ Accept : 'application/json' ,
12+ Authorization : `Bearer ${ process . env . FRONTEND_SECRET } ` ,
13+ } ,
14+ body : JSON . stringify ( { paths, tags } ) ,
15+ } )
16+
17+ const data = await res . json ( )
18+ return { revalidated : data . revalidated || res . ok }
19+ } catch ( e : any ) {
20+ console . error ( e )
21+ return { revalidated : false }
22+ }
23+ }
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { SyncClaimOsmTask } from './claims/syncClaimOsm.task'
88import { SendDiscordDmTask } from './discord/sendDm.task'
99import { SendDiscordLogTask } from './discord/sendLog.task'
1010import { SyncDiscordRolesTask } from './discord/syncDiscordRoles.task'
11+ import { RevalidateWebsitePageTask } from './website/revalidatePage.task'
1112
1213export const taskRegistry : Record < string , BaseTask > = { }
1314
@@ -24,3 +25,4 @@ register(new PurgeVerificationsTask())
2425register ( new RemindApplicationsTask ( ) )
2526register ( new SyncClaimOsmTask ( ) )
2627register ( new SyncDiscordRolesTask ( ) )
28+ register ( new RevalidateWebsitePageTask ( ) )
Original file line number Diff line number Diff line change 1+ import { Job } from 'bullmq'
2+ import { z } from 'zod'
3+ import { revalidateWebsitePage } from '../../lib/website'
4+ import { BaseTask } from '../base.task'
5+
6+ const revalidateWebsitePagePayloadSchema = z . object ( {
7+ paths : z . array ( z . string ( ) ) . optional ( ) ,
8+ tags : z . array ( z . string ( ) ) . optional ( ) ,
9+ } )
10+
11+ type RevalidateWebsitePagePayload = z . infer < typeof revalidateWebsitePagePayloadSchema >
12+
13+ /**
14+ * This task sends a revalidation request to the frontend server for specific website pages. It can either revalidate specific paths or whole tags.
15+ * @summary Revalidates specific website pages
16+ */
17+ export class RevalidateWebsitePageTask extends BaseTask < typeof revalidateWebsitePagePayloadSchema > {
18+ readonly name = 'REVALIDATE_WEBSITE'
19+ readonly schema = revalidateWebsitePagePayloadSchema
20+
21+ async execute ( data : RevalidateWebsitePagePayload , job : Job ) {
22+ const { paths, tags } = data
23+
24+ if ( paths && paths . length < 1 && tags && tags . length < 1 ) {
25+ return
26+ }
27+
28+ const { revalidated } = await revalidateWebsitePage ( paths , tags )
29+
30+ if ( ! revalidated ) {
31+ throw new Error ( 'Failed to revalidate website page' )
32+ }
33+ }
34+ }
Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ export enum RedisEvent {
77 BUILDTEAM_WEBHOOK = 'BUILDTEAM_WEBHOOK' ,
88 SYNC_CLAIM_OSM = 'SYNC_CLAIM_OSM' ,
99 SYNC_DISCORD_ROLES = 'SYNC_DISCORD_ROLES' ,
10+ REVALIDATE_WEBSITE = 'REVALIDATE_WEBSITE' ,
1011}
1112
1213/**
You can’t perform that action at this time.
0 commit comments