Skip to content

Commit 107e6c5

Browse files
oskarrisbergclaude
andcommitted
Add failed job clearer script and bump dotenv
Add clearer.js to remove 409 conflict failed jobs from the reddit-posts queue. Bump dotenv from 8.x to 16.x. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent e13f621 commit 107e6c5

3 files changed

Lines changed: 5477 additions & 1989 deletions

File tree

clearer.js

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
require('dotenv').config();
2+
3+
const Queue = require( 'bull' );
4+
5+
if ( !process.env.REDIS_URL ) {
6+
throw new Error( 'Got no queue, exiting' );
7+
}
8+
9+
const redditQueue = new Queue(
10+
'reddit-posts',
11+
process.env.REDIS_URL,
12+
{
13+
limiter: {
14+
max: 1,
15+
duration: 2000, // Might be 2 requests / post (content & parent)
16+
},
17+
}
18+
);
19+
20+
let lastFailCount = false;
21+
22+
redditQueue.on( 'error', ( queueError ) => {
23+
console.error( queueError );
24+
} );
25+
26+
redditQueue.on( 'failed', ( job, jobError ) => {
27+
console.error( jobError );
28+
} );
29+
30+
const removeCollisions = async function removeCollisions(){
31+
let failedCount = false;
32+
try {
33+
failedCount = await redditQueue.getFailedCount();
34+
} catch (failedCountError){
35+
console.error(failedCountError);
36+
}
37+
38+
if(failedCount === 0){
39+
return true;
40+
}
41+
42+
if(lastFailCount === failedCount){
43+
console.log(`No jobs removed, stopping`);
44+
45+
return true;
46+
}
47+
48+
lastFailCount = failedCount;
49+
50+
console.log(failedCount);
51+
52+
let jobs;
53+
54+
try {
55+
jobs = await redditQueue.getFailed(0, Math.min(100, failedCount));
56+
} catch (someError){
57+
console.log(someError);
58+
}
59+
60+
for(const job of jobs){
61+
if(!job.failedReason.includes('/posts returned 409')){
62+
console.log(job.failedReason);
63+
64+
continue;
65+
}
66+
67+
try {
68+
await job.remove();
69+
} catch (removeError){
70+
console.error(removeError);
71+
}
72+
}
73+
74+
return await removeCollisions();
75+
};
76+
77+
( async () => {
78+
await removeCollisions();
79+
80+
redditQueue.close();
81+
})();
82+

0 commit comments

Comments
 (0)