Skip to content

Commit 514fab3

Browse files
committed
[api refactor] Minor refactoring (usage)
1 parent 6fefca1 commit 514fab3

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

bin/packuments-fetch-all-partitions.js

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,27 @@
11
const { listPartitionsSync } = require('../src/cache.js');
2-
const { cachePackumentsSeries, getPackumentsLimit } = require('../src/packument.js');
3-
const { readFileSync } = require('node:fs');
4-
const { writeFile } = require('node:fs/promises');
52
const { join } = require('node:path');
6-
const { execSync, exec } = require('node:child_process');
7-
const { DRY_RUN } = require('../src/env.js');
3+
const { execSync, spawn } = require('node:child_process');
84

95
const debug = require('debug')('_all_docs/packuments-fetch-for-partition');
106

117
const cacheDir = join(__dirname, '..', 'cache');
12-
const packumentsDir = join(cacheDir, 'packuments');
13-
148
const partitions = listPartitionsSync(cacheDir);
159

1610
function execFetchPackuments(partition) {
1711
const command = `node bin/packuments-fetch-for-partition.js ${partition.id}`;
1812

19-
debug('fetch packuments |', {
13+
debug('exec fetch packuments |', {
2014
command,
2115
partition: partition.id
2216
});
2317

2418
execSync(command, {
2519
cwd: join(__dirname, '..'),
20+
stdio: ['ignore', 'inherit', 'inherit'],
2621
env: {
22+
...process.env,
2723
CONCURRENCY: 100,
28-
SIZE: 2000,
29-
PARTITIONS: process.env.PARTITIONS,
30-
DEBUG: process.env.DEBUG,
31-
DRY_RUN: process.env.DRY_RUN
24+
SIZE: 2000
3225
}
3326
});
3427
}

bin/packuments-fetch-for-partition.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ const { cachePackumentsLimit } = require('../src/packument.js');
22
const { readFileSync } = require('node:fs');
33
const { writeFile } = require('node:fs/promises');
44
const { join } = require('node:path');
5+
const delay = require('delay').default;
56

67
const debug = require('debug')('_all_docs/packuments-fetch-for-partition');
78

@@ -34,5 +35,10 @@ const partition = JSON.parse(
3435
debug('cache packument | ', { _id, _rev, cached: ++cached });
3536

3637
writeFile(join(packumentsDir, `${_id}.json`), JSON.stringify(packument));
37-
}, limit);
38+
}, {
39+
limit,
40+
cacheDir: packumentsDir
41+
});
42+
43+
await delay(1000 * 30)
3844
})();

bin/partitions-fetch-from-origin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const {
99
DRY_RUN
1010
} = require('../src/env');
1111

12-
const { isPartitionCached } = require('../src/cache');
12+
const { isJsonCached } = require('../src/cache');
1313
const { eachLimit } = require('../src/map-reduce');
1414
const { writePartition } = require('../src/index');
1515

@@ -31,7 +31,7 @@ async function getPartitionRange({ limit, range }) {
3131

3232
let misses = 0;
3333
await eachLimit(targets, limit, async function eachFn(partition) {
34-
const cached = await isPartitionCached(partition);
34+
const cached = await isJsonCached(partition.filename);
3535
if (!cached && !DRY_RUN) {
3636
misses = misses + 1;
3737
await writePartition({ partition });

0 commit comments

Comments
 (0)