Spaces:
Runtime error
Runtime error
Niv Sardi
commited on
Commit
·
9f5528c
1
Parent(s):
258f7cd
deno: idle until csv shows up
Browse filesSigned-off-by: Niv Sardi <xaiki@evilgiggle.com>
- src/index.ts +15 -4
src/index.ts
CHANGED
|
@@ -10,12 +10,11 @@ const queue = new PQueue({
|
|
| 10 |
timeout: 60000
|
| 11 |
})
|
| 12 |
let count = 0
|
|
|
|
| 13 |
queue.addEventListener("active", () =>
|
| 14 |
console.log(`Working on item #${++count}. Size: ${queue.size} Pending: ${queue.pending}`))
|
| 15 |
queue.addEventListener("next", () =>
|
| 16 |
console.log(`task finished, Size: ${queue.size} Pending: ${queue.pending}`))
|
| 17 |
-
const statInterval = setInterval(() =>
|
| 18 |
-
console.log(`Size: ${queue.size} Pending: ${queue.pending}`), 1000);
|
| 19 |
|
| 20 |
queue.addEventListener("idle", async () => {
|
| 21 |
clearInterval(statInterval)
|
|
@@ -67,5 +66,17 @@ function process(o: { url: string, bco: string, name: string }): Promise<void> {
|
|
| 67 |
})
|
| 68 |
}
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
timeout: 60000
|
| 11 |
})
|
| 12 |
let count = 0
|
| 13 |
+
let statInterval
|
| 14 |
queue.addEventListener("active", () =>
|
| 15 |
console.log(`Working on item #${++count}. Size: ${queue.size} Pending: ${queue.pending}`))
|
| 16 |
queue.addEventListener("next", () =>
|
| 17 |
console.log(`task finished, Size: ${queue.size} Pending: ${queue.pending}`))
|
|
|
|
|
|
|
| 18 |
|
| 19 |
queue.addEventListener("idle", async () => {
|
| 20 |
clearInterval(statInterval)
|
|
|
|
| 66 |
})
|
| 67 |
}
|
| 68 |
|
| 69 |
+
async function run() {
|
| 70 |
+
let text;
|
| 71 |
+
try {
|
| 72 |
+
text = await Deno.readTextFile("./data/entidades.csv")
|
| 73 |
+
} catch (e) {
|
| 74 |
+
console.error(`couldn't read csv: ${e}`)
|
| 75 |
+
}
|
| 76 |
+
if (!text) return setTimeout(run, 1000)
|
| 77 |
+
statInterval = setInterval(() =>
|
| 78 |
+
console.log(`Size: ${queue.size} Pending: ${queue.pending}`), 1000);
|
| 79 |
+
|
| 80 |
+
CSV.parse(text, o => queue.add(() => process(o)))
|
| 81 |
+
}
|
| 82 |
+
run()
|