-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbull-script.mjs
46 lines (35 loc) · 1.14 KB
/
bull-script.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import fetch from "node-fetch";
import "dotenv/config";
const URL = process.env.URL;
const START_PAGE = process.env.START_PAGE;
const END_PAGE = process.env.END_PAGE;
console.log('Starting...')
console.log('Configs: ', URL, ' / ', START_PAGE, ' - ', END_PAGE)
async function retryJobs(jobsArray) {
await Promise.all(jobsArray.map( async (jobId)=> {
await fetch(`${URL}/api/queues/UseCaseJob/${jobId}/retry`, {method: 'put'})
}))
}
async function wait(waitingTime) {
await new Promise((resolve, reject) => {
if ( waitingTime < 0 ){
reject('waitingTime is not a valid Value')
}
console.log('waiting for ', waitingTime/1000, ' seconds')
setTimeout(resolve, waitingTime)
})
}
process.on('uncaughtException', function (exception) {
console.log(exception)
});
for (let i = START_PAGE; i >= END_PAGE; i--) {
if( i % 100 === 0) {
console.log(i)
}
const response = await fetch(
`${URL}/api/queues?activeQueue=UseCaseJob&status=failed&page=${i}`,
{ method: "get" }
)
const jobsIds = (await response.json()).queues[0].jobs.map(element => element.id)
retryJobs(jobsIds).catch((error) => { console.log(error)})
}