[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
+97 -58

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
+96 -58
View File
@@ -34,23 +34,27 @@ 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) {
if (path.extname(file) === '.png') { if (path.extname(file) === '.png') {
fs.unlinkSync(path.join(attachmentDestination, file)); fs.unlinkSync(path.join(attachmentDestination, file));
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,59 +135,91 @@ 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));
}
function fail(error) {
console.error('Error:', error);
process.exit(1); process.exit(1);
}, 10 * 60 * 1000); }
imap.once('ready', async () => { function connectAsync() {
try { return new Promise((resolve, reject) => {
await openBoxAsync('INBOX'); 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();
});
}
const now = new Date(); async function connectWithRetryAsync() {
const yesterday = new Date(now - 24 * 60 * 60 * 1000); for (let attempt = 1; ; attempt++) {
const yesterdayString = yesterday.toISOString().slice(0, 19).replace('T', ' '); try {
await connectAsync();
deleteExistingAttachments(); return;
} catch (error) {
const images = [] if (attempt === CONNECT_ATTEMPTS) {
images.push({ throw error;
title: 'App Health', }
filename: await getAttachementAsync('bdp_noreply@data.roku.com', 'App Health', yesterdayString) console.error('Connection attempt %d/%d failed: %s', attempt, CONNECT_ATTEMPTS, error.message);
}) await sleep(RETRY_DELAY_MS);
images.push({ }
title: 'App Engagement',
filename: await getAttachementAsync('bdp_noreply@data.roku.com', 'App Engagement', yesterdayString)
})
images.push({
title: 'Viewership Summary',
filename: await getAttachementAsync('bdp_noreply@data.roku.com', 'Viewership Summary', yesterdayString)
})
images.push({
title: 'App Stability',
filename: await getAttachementAsync('bdp_noreply@data.roku.com', 'App Stability', yesterdayString)
})
writeMarkDownFile(images);
await moveToTrash('bdp_noreply@data.roku.com', 'App Health', yesterdayString);
await moveToTrash('bdp_noreply@data.roku.com', 'App Engagement', yesterdayString);
await moveToTrash('bdp_noreply@data.roku.com', 'Viewership Summary', yesterdayString);
await moveToTrash('bdp_noreply@data.roku.com', 'App Stability', yesterdayString);
imap.end();
} catch (error) {
console.error('Error:', error);
} }
clearTimeout(timeout); }
});
imap.once('error', err => { async function downloadStats() {
console.error(err); await connectWithRetryAsync();
}); await openBoxAsync('INBOX');
imap.once('end', () => { const now = new Date();
const yesterday = new Date(now - 24 * 60 * 60 * 1000);
const yesterdayString = yesterday.toISOString().slice(0, 19).replace('T', ' ');
deleteExistingAttachments();
const images = []
images.push({
title: 'App Health',
filename: await getAttachementAsync('bdp_noreply@data.roku.com', 'App Health', yesterdayString)
})
images.push({
title: 'App Engagement',
filename: await getAttachementAsync('bdp_noreply@data.roku.com', 'App Engagement', yesterdayString)
})
images.push({
title: 'Viewership Summary',
filename: await getAttachementAsync('bdp_noreply@data.roku.com', 'Viewership Summary', yesterdayString)
})
images.push({
title: 'App Stability',
filename: await getAttachementAsync('bdp_noreply@data.roku.com', 'App Stability', yesterdayString)
})
writeMarkDownFile(images);
await moveToTrash('bdp_noreply@data.roku.com', 'App Health', yesterdayString);
await moveToTrash('bdp_noreply@data.roku.com', 'App Engagement', yesterdayString);
await moveToTrash('bdp_noreply@data.roku.com', 'Viewership Summary', yesterdayString);
await moveToTrash('bdp_noreply@data.roku.com', 'App Stability', yesterdayString);
imap.end();
}
imap.on('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);