@@ -2,33 +2,35 @@ import process from 'node:process';
22import { setFailed } from '@actions/core' ;
33import { generateAllIndices } from '@discordjs/scripts' ;
44import Cloudflare from 'cloudflare' ;
5- import { MeiliSearch } from 'meilisearch' ;
5+ import { type EnqueuedTask , MeiliSearch } from 'meilisearch' ;
66import pLimit from 'p-limit' ;
77import { fetch } from 'undici' ;
88
9- if ( ! ( process . env . CF_D1_DOCS_API_KEY && process . env . CF_D1_DOCS_ID && process . env . CF_ACCOUNT_ID ) ) {
9+ if ( ! process . env . CF_D1_DOCS_API_KEY || ! process . env . CF_D1_DOCS_ID || ! process . env . CF_ACCOUNT_ID ) {
1010 setFailed ( 'Missing Cloudflare D1 environment variables.' ) ;
11+ process . exit ( 1 ) ;
1112}
1213
1314if ( ! process . env . SEARCH_API_URL ) {
1415 setFailed ( 'SEARCH_API_URL is not set' ) ;
16+ process . exit ( 1 ) ;
1517}
1618
1719if ( ! process . env . SEARCH_API_KEY ) {
1820 setFailed ( 'SEARCH_API_KEY is not set' ) ;
21+ process . exit ( 1 ) ;
1922}
2023
2124const cf = new Cloudflare ( {
22- apiToken : process . env . CF_D1_DOCS_API_KEY ! ,
25+ apiToken : process . env . CF_D1_DOCS_API_KEY ,
2326} ) ;
2427
2528const client = new MeiliSearch ( {
26- host : process . env . SEARCH_API_URL ! ,
27- apiKey : process . env . SEARCH_API_KEY ! ,
29+ host : process . env . SEARCH_API_URL ,
30+ apiKey : process . env . SEARCH_API_KEY ,
2831} ) ;
2932
30- const limit = pLimit ( 10 ) ;
31- let promises : Promise < any > [ ] = [ ] ;
33+ const limit = pLimit ( 5 ) ;
3234
3335try {
3436 console . log ( 'Generating all indices...' ) ;
@@ -62,35 +64,31 @@ try {
6264
6365 console . log ( 'Uploading indices...' ) ;
6466
65- try {
66- promises = indices . map ( async ( index ) =>
67- limit ( async ( ) => {
68- console . log ( `Uploading ${ index . index } ...` ) ;
69- let task ;
70- try {
71- task = await client . createIndex ( index . index ) ;
72- } catch { }
67+ const promises = indices . map ( async ( index ) =>
68+ limit ( async ( ) => {
69+ console . log ( `Uploading ${ index . index } ...` ) ;
70+ let task : EnqueuedTask | undefined ;
71+ try {
72+ task = await client . createIndex ( index . index ) ;
73+ } catch { }
7374
74- if ( task ) {
75- await client . waitForTask ( task . taskUid ) ;
76- }
75+ if ( task ) {
76+ await client . tasks . waitForTask ( task , { timeout : 10_000 } ) ;
77+ }
7778
78- const searchIndex = client . index ( index . index ) ;
79- await searchIndex . updateSettings ( { sortableAttributes : [ 'type' ] } ) ;
79+ const searchIndex = client . index ( index . index ) ;
80+ await searchIndex . updateSettings ( { sortableAttributes : [ 'type' ] } ) ;
8081
81- await searchIndex . addDocuments ( index . data ) ;
82- } ) ,
83- ) ;
84- } catch { }
82+ await searchIndex . addDocuments ( index . data ) ;
83+ } ) ,
84+ ) ;
85+
86+ await Promise . all ( promises ) ;
8587
8688 console . log ( 'Uploaded all indices.' ) ;
8789} catch ( error ) {
8890 const err = error as Error ;
91+ console . error ( err ) ;
8992 setFailed ( err . message ) ;
90- }
91-
92- try {
93- await Promise . all ( promises ) ;
94- } catch ( error ) {
95- console . log ( error ) ;
93+ process . exit ( 1 ) ;
9694}
0 commit comments