Skip to content

Commit

Permalink
Continue piscina try
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasG77 committed Apr 4, 2023
1 parent 8631b7c commit 284d294
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 19 deletions.
2 changes: 0 additions & 2 deletions lib/commands/generate-shp.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ async function handler(workDir) {

console.timeEnd(' terminé')

await stopWorkers()

console.log()
console.log('Finished!')
}
Expand Down
12 changes: 5 additions & 7 deletions lib/extract/departement.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import {createRequire} from 'node:module'
import {EventEmitter} from 'node:events'
import {Piscina} from 'piscina'
import bluebird from 'bluebird'
import {Tree} from '../dist/pci.js'

const require = createRequire(import.meta.url)

const extractCommuneWorkers = new Piscina({
filename: new URL('./worker.js', import.meta.url).href,
filename: new URL('worker.js', import.meta.url).href,
})

function extractDepartement(basePath, codeDep) {
Expand All @@ -28,15 +25,16 @@ function extractDepartement(basePath, codeDep) {

// Series since GDAL is a blocking binding
// eslint-disable-next-line unicorn/no-array-method-this-argument, unicorn/no-array-callback-reference
return bluebird.map(communesFound, commune => new Promise((resolve, reject) => {
return bluebird.map(communesFound, commune => {
try {
await extractCommuneWorkers.run({basePath, codeCommune: commune})
progress({codeCommune: commune})
return extractCommuneWorkers.run({basePath, codeCommune: commune})
} catch (error) {
console.error('Unable to extract commune %s', commune)
console.error(error)
return Promise.reject(error)
}
}))
})
})
.then(() => extractor.emit('end'))
.catch(error => extractor.emit('error', error))
Expand Down
4 changes: 1 addition & 3 deletions lib/merge/index.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import {createRequire} from 'node:module'
import os from 'node:os'
import {Piscina} from 'piscina'

const mergeWorkers = new Piscina({
filename: new URL('./worker.js', import.meta.url).href,
filename: new URL('worker.js', import.meta.url).href,
})

function mergeGeoJSONFiles(options) {
Expand Down
8 changes: 1 addition & 7 deletions lib/shp/index.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,7 @@
import os from 'node:os'
import {createRequire} from 'node:module'
import {promisify} from 'node:util'
import {Piscina} from 'piscina'

const require = createRequire(import.meta.url)
const concurrency = Math.min(os.cpus().length, 8)

const shpWorkers = new Piscina({
filename: new URL('./worker.js', import.meta.url).href,
filename: new URL('worker.js', import.meta.url).href,
})

function convertToShape(srcPath, destPath, {layer, targetCrs}) {
Expand Down

0 comments on commit 284d294

Please sign in to comment.