[skip ci] ci fix

This commit is contained in:
Brahim Hadriche committed 2026-08-15 10:24:54 -04:00
1 parent fea1c22aa9
commit 9da9bdf06f
2 files changed
+60 -21

No files matched your search

+1
View File
@@ -8,6 +8,7 @@ on:
jobs: jobs:
update_wiki_stats: update_wiki_stats:
runs-on: ubuntu-latest runs-on: ubuntu-latest
timeout-minutes: 20
steps: steps:
- name: Checkout - name: Checkout
uses: actions/checkout@v4 uses: actions/checkout@v4
+59 -21
View File
@@ -34,8 +34,7 @@ This page was automatically generated on ${formattedDate}.
fs.writeFileSync(markdownFile, markdownContent); fs.writeFileSync(markdownFile, markdownContent);
} }
async function deleteExistingAttachments() { function deleteExistingAttachments() {
try {
const files = fs.readdirSync(attachmentDestination); const files = fs.readdirSync(attachmentDestination);
for (const file of files) { for (const file of files) {
@@ -44,13 +43,18 @@ async function deleteExistingAttachments() {
console.log(`Deleted ${file}`); console.log(`Deleted ${file}`);
} }
} }
} catch (error) {
console.error(error);
}
} }
const config = getEnvVars(['EMAIL', 'EMAIL_APP_PASSWORD']); const config = getEnvVars(['EMAIL', 'EMAIL_APP_PASSWORD']);
// Gmail can take 15s or more to answer LOGIN, well past node-imap's 5s default,
// and throttles an account that reconnects right after a failed attempt.
const AUTH_TIMEOUT_MS = 60 * 1000;
const CONNECT_TIMEOUT_MS = 30 * 1000;
const CONNECT_ATTEMPTS = 3;
const RETRY_DELAY_MS = 30 * 1000;
const RUN_TIMEOUT_MS = 10 * 60 * 1000;
const imap = new Imap({ const imap = new Imap({
user: config.EMAIL, user: config.EMAIL,
password: config.EMAIL_APP_PASSWORD, password: config.EMAIL_APP_PASSWORD,
@@ -59,7 +63,9 @@ const imap = new Imap({
tls: true, tls: true,
tlsOptions: { tlsOptions: {
rejectUnauthorized: false rejectUnauthorized: false
} },
connTimeout: CONNECT_TIMEOUT_MS,
authTimeout: AUTH_TIMEOUT_MS
}); });
const searchAsync = promisify(imap.search).bind(imap); const searchAsync = promisify(imap.search).bind(imap);
@@ -129,13 +135,49 @@ async function moveToTrash(from, subject, since) {
console.log('Moved %d message(s) to Trash for subject "%s"', uids.length, subject); console.log('Moved %d message(s) to Trash for subject "%s"', uids.length, subject);
} }
const timeout = setTimeout(() => { function sleep(ms) {
console.log('Timeout'); return new Promise(resolve => setTimeout(resolve, ms));
process.exit(1); }
}, 10 * 60 * 1000);
imap.once('ready', async () => { function fail(error) {
console.error('Error:', error);
process.exit(1);
}
function connectAsync() {
return new Promise((resolve, reject) => {
const onReady = () => {
imap.removeListener('error', onError);
imap.on('error', fail);
resolve();
};
const onError = error => {
imap.removeListener('ready', onReady);
reject(error);
};
imap.once('ready', onReady);
imap.once('error', onError);
imap.connect();
});
}
async function connectWithRetryAsync() {
for (let attempt = 1; ; attempt++) {
try { try {
await connectAsync();
return;
} catch (error) {
if (attempt === CONNECT_ATTEMPTS) {
throw error;
}
console.error('Connection attempt %d/%d failed: %s', attempt, CONNECT_ATTEMPTS, error.message);
await sleep(RETRY_DELAY_MS);
}
}
}
async function downloadStats() {
await connectWithRetryAsync();
await openBoxAsync('INBOX'); await openBoxAsync('INBOX');
const now = new Date(); const now = new Date();
@@ -170,18 +212,14 @@ imap.once('ready', async () => {
await moveToTrash('bdp_noreply@data.roku.com', 'App Stability', yesterdayString); await moveToTrash('bdp_noreply@data.roku.com', 'App Stability', yesterdayString);
imap.end(); imap.end();
} catch (error) {
console.error('Error:', error);
} }
clearTimeout(timeout);
});
imap.once('error', err => { imap.on('end', () => {
console.error(err);
});
imap.once('end', () => {
console.log('Connection ended'); console.log('Connection ended');
}); });
imap.connect(); setTimeout(() => fail(new Error(`Gave up after ${RUN_TIMEOUT_MS / 1000}s`)), RUN_TIMEOUT_MS);
downloadStats().then(() => {
process.exit(0);
}).catch(fail);