diff --git a/cmds/eval.js b/cmds/eval.js index ea85cbd6..2f2b1a5c 100644 --- a/cmds/eval.js +++ b/cmds/eval.js @@ -134,6 +134,29 @@ function checkWiki(wiki) { db.query( 'SELECT pg_notify($1, $2)', ['webhookupdates', 'DEBUG WIKI ' + result.wiki] ).catch( dberror => { result.webhookupdates = dberror.toString(); } ), + new Promise( (resolve, reject) => { + console.log( '- Requesting RcGcDb debug dump for ' + result.wiki ); + let id = process.env.SHARDS + '+' + Date.now(); + let timeout = setTimeout( () => { + dbListenerMap.delete(id); + reject('Timeout'); + }, 5000 ).unref(); + dbListenerMap.set(id, {timeout, body: '', resolve}); + db.query( 'SELECT pg_notify($1, $2)', ['webhookupdates', 'DEBUG SITE ' + id + ' ' + result.wiki] ).catch( dberror => { + console.log( '- Dashboard: Error while requesting the debug dump for ' + result.wiki + ': ' + dberror ); + dbListenerMap.delete(id); + clearTimeout(timeout); + reject(dberror); + } ); + } ).then( jsonBody => { + let body = JSON.parse(jsonBody); + delete body.logs; + delete body.tags; + delete body.namespaces; + result.debug = body; + } ).catch( error => { + result.debug = {error}; + } ), ( wiki.wikifarm === 'fandom' ? got.get( wiki + 'wikia.php?controller=DiscussionPost&method=getPosts&includeCounters=false&sortDirection=descending&sortKey=creation_date&limit=100&format=json&cache=' + Date.now(), { headers: { Accept: 'application/hal+json' diff --git a/main.js b/main.js index abd7c44d..a0e843b5 100644 --- a/main.js +++ b/main.js @@ -493,6 +493,22 @@ db.on( 'notification', msg => { }; return; } + manager.broadcastEval( (discordClient, message) => { + let listener = globalThis.dbListenerMap.get(message.listener); + if ( !listener ) return; + if ( message.part === 'CHUNK' ) { + return listener.body += message.data; + } + if ( message.part === 'END' ) { + globalThis.dbListenerMap.delete(message.listener); + clearTimeout(listener.timeout); + listener.resolve(listener.body); + return; + } + }, {context: { + type, part, listener, + data: payload.join(' ') + }, shard} ); } } ); diff --git a/util/globals.js b/util/globals.js index fab0a6b6..d98148cd 100644 --- a/util/globals.js +++ b/util/globals.js @@ -48,6 +48,12 @@ globalThis.patreonGuildsPrefix = new Map(); */ globalThis.pausedGuilds = new Set(); +/** + * Map of database event listeners + * @type {Map} + */ +globalThis.dbListenerMap = new Map(); + /** * Logs an error. * @param {Error} error - The error.