File tree Expand file tree Collapse file tree 4 files changed +39
-0
lines changed
Expand file tree Collapse file tree 4 files changed +39
-0
lines changed Original file line number Diff line number Diff line change @@ -9,5 +9,9 @@ export default {
99 "expires_at" timestamptz NOT NULL,
1010 CONSTRAINT "dedupe_pk" PRIMARY KEY ("task_name", "dedupe_key")
1111 );
12+
13+ CREATE INDEX "graphile_worker_deduplication_expires_at_idx"
14+ ON "graphile_worker_deduplication" ("expires_at")
15+ ;
1216 ` ,
1317} satisfies MigrationExecutor ;
Original file line number Diff line number Diff line change @@ -135,6 +135,12 @@ export interface document_preflight_scripts {
135135 updated_at : Date ;
136136}
137137
138+ export interface graphile_worker_deduplication {
139+ dedupe_key : string ;
140+ expires_at : Date ;
141+ task_name : string ;
142+ }
143+
138144export interface migration {
139145 date : Date ;
140146 hash : string ;
@@ -441,6 +447,7 @@ export interface DBTables {
441447 document_collection_documents : document_collection_documents ;
442448 document_collections : document_collections ;
443449 document_preflight_scripts : document_preflight_scripts ;
450+ graphile_worker_deduplication : graphile_worker_deduplication ;
444451 migration : migration ;
445452 oidc_integrations : oidc_integrations ;
446453 organization_access_tokens : organization_access_tokens ;
Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ const modules = await Promise.all([
3535 import ( './tasks/organization-invitation.js' ) ,
3636 import ( './tasks/organization-ownership-transfer.js' ) ,
3737 import ( './tasks/password-reset.js' ) ,
38+ import ( './tasks/purge-expired-dedupe-keys.js' ) ,
3839 import ( './tasks/purge-expired-schema-checks.js' ) ,
3940 import ( './tasks/schema-change-notification.js' ) ,
4041 import ( './tasks/usage-rate-limit-exceeded.js' ) ,
@@ -44,6 +45,8 @@ const modules = await Promise.all([
4445const crontab = `
4546 # Purge expired schema checks every Sunday at 10:00AM
4647 0 10 * * 0 purgeExpiredSchemaChecks
48+ # Every day at 3:00 AM
49+ 0 3 * * * purgeExpiredDedupeKeys
4750` ;
4851
4952const pg = await createPool ( env . postgres . connectionString ) ;
Original file line number Diff line number Diff line change 1+ import { sql } from 'slonik' ;
2+ import { z } from 'zod' ;
3+ import { defineTask , implementTask } from '../kit.js' ;
4+
5+ export const PurgeExpiredDedupeKeysTask = defineTask ( {
6+ name : 'purgeExpiredDedupeKeys' ,
7+ schema : z . unknown ( ) ,
8+ } ) ;
9+
10+ export const task = implementTask ( PurgeExpiredDedupeKeysTask , async args => {
11+ args . logger . debug ( 'purging expired postgraphile task dedupe keys' ) ;
12+ const result = await args . context . pg . oneFirst ( sql `
13+ WITH "deleted" AS (
14+ DELETE FROM "graphile_worker_deduplication"
15+ WHERE "expires_at" < NOW()
16+ RETURNING 1
17+ )
18+ SELECT COUNT(*) FROM "deleted";
19+ ` ) ;
20+ const amount = z . number ( ) . parse ( result ) ;
21+ args . logger . debug (
22+ { purgedCount : amount } ,
23+ 'finished purging expired postgraphile task dedupe keys' ,
24+ ) ;
25+ } ) ;
You can’t perform that action at this time.
0 commit comments