Skip to content

Commit

Permalink
make checkWiki show debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
Markus-Rost committed Jul 25, 2024
1 parent 1e9a8b2 commit 15af5fd
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
23 changes: 23 additions & 0 deletions cmds/eval.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
16 changes: 16 additions & 0 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -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} );
}
} );

Expand Down
6 changes: 6 additions & 0 deletions util/globals.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ globalThis.patreonGuildsPrefix = new Map();
*/
globalThis.pausedGuilds = new Set();

/**
* Map of database event listeners
* @type {Map<Number, {timeout: NodeJS.Timeout, body: String, resolve: PromiseConstructor.resolve}>}
*/
globalThis.dbListenerMap = new Map();

/**
* Logs an error.
* @param {Error} error - The error.
Expand Down

0 comments on commit 15af5fd

Please sign in to comment.