mobiletto 1.1.33 → 1.1.34
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +20 -13
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -465,31 +465,22 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
|
|
|
465
465
|
const _singleMeta = async (job) => {
|
|
466
466
|
const dirent = job.data.dirent
|
|
467
467
|
const entry = job.data.entry
|
|
468
|
-
const files = job.data.files
|
|
469
468
|
const logPrefix = `_singleMeta(${dirent}/${basename(entry.name)})`
|
|
470
|
-
// every outcome always pushes something onto the files array
|
|
471
|
-
// this is because we know we're done when files.length === entries.length, even if
|
|
472
|
-
// some items in the files array are error messages instead of metadata objects
|
|
473
469
|
return new Promise((resolve, reject) => {
|
|
474
470
|
const cipherText = []
|
|
475
471
|
client.read(dirent + '/' + basename(entry.name), reader(cipherText))
|
|
476
472
|
.then((bytesRead) => {
|
|
477
473
|
if (!bytesRead) {
|
|
478
474
|
logger.warn(`${logPrefix} returned no data`)
|
|
479
|
-
files.push({})
|
|
480
475
|
resolve({})
|
|
481
476
|
} else {
|
|
482
477
|
const plain = decrypt(cipherText.toString(), enc)
|
|
483
478
|
const realPath = plain.split(ENC_PAD_SEP)[0]
|
|
484
479
|
_metadata(client)(realPath)
|
|
485
|
-
.then(
|
|
486
|
-
files.push(meta)
|
|
487
|
-
resolve(meta)
|
|
488
|
-
})
|
|
480
|
+
.then(meta => resolve(meta))
|
|
489
481
|
.catch((err) => {
|
|
490
482
|
const message = `${logPrefix} error fetching _metadata: ${err}`
|
|
491
483
|
logger.warn(message)
|
|
492
|
-
files.push(message)
|
|
493
484
|
reject(message)
|
|
494
485
|
})
|
|
495
486
|
}
|
|
@@ -497,7 +488,6 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
|
|
|
497
488
|
.catch((err) => {
|
|
498
489
|
const message = `${logPrefix} error reading file: ${err}`
|
|
499
490
|
logger.warn(message)
|
|
500
|
-
files.push(message)
|
|
501
491
|
reject(message)
|
|
502
492
|
})
|
|
503
493
|
})
|
|
@@ -515,9 +505,20 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
|
|
|
515
505
|
throw new MobilettoError(message)
|
|
516
506
|
}
|
|
517
507
|
META_LOAD_QUEUE = new Queue(META_LOAD_QUEUE_NAME, `redis://${client.redisConfig.host || '127.0.0.1'}:${client.redisConfig.port || 6379}`)
|
|
508
|
+
META_LOAD_QUEUE.mobilettoHandlers = {}
|
|
509
|
+
META_LOAD_QUEUE.mobilettoErrorHandlers = {}
|
|
518
510
|
META_LOAD_QUEUE.process(META_LOAD_JOB_NAME, META_LOAD_CONCURRENCY, _singleMeta)
|
|
519
511
|
META_LOAD_QUEUE.on('completed', function (job, result) {
|
|
520
512
|
logger.info(`${META_LOAD_JOB_NAME} completed with result: ${JSON.stringify(result)}`)
|
|
513
|
+
if (job.data.jobId && META_LOAD_QUEUE.mobilettoHandlers[job.data.jobId]) {
|
|
514
|
+
META_LOAD_QUEUE.mobilettoHandlers[job.data.jobId](result)
|
|
515
|
+
}
|
|
516
|
+
})
|
|
517
|
+
META_LOAD_QUEUE.on('failed', function (job, result) {
|
|
518
|
+
logger.info(`${META_LOAD_JOB_NAME} failed with result: ${JSON.stringify(result)}`)
|
|
519
|
+
if (job.data.jobId && META_LOAD_QUEUE.mobilettoErrorHandlers[job.data.jobId]) {
|
|
520
|
+
META_LOAD_QUEUE.mobilettoErrorHandlers[job.data.jobId](result)
|
|
521
|
+
}
|
|
521
522
|
})
|
|
522
523
|
}
|
|
523
524
|
return META_LOAD_QUEUE
|
|
@@ -534,11 +535,17 @@ async function mobiletto (driverPath, key, secret, opts, encryption = null) {
|
|
|
534
535
|
}
|
|
535
536
|
}
|
|
536
537
|
|
|
538
|
+
const jobId = randomstring.generate(10)
|
|
539
|
+
const mq = metaLoadQueue()
|
|
540
|
+
mq.mobilettoHandlers[jobId] = meta => files.push(meta)
|
|
541
|
+
mq.mobilettoErrorHandlers[jobId] = err => files.push(err)
|
|
537
542
|
for (const entry of entries) {
|
|
538
|
-
const job = { dirent, entry, files }
|
|
539
|
-
|
|
543
|
+
const job = { jobId, dirent, entry, files }
|
|
544
|
+
mq.add(META_LOAD_JOB_NAME, job)
|
|
540
545
|
}
|
|
541
546
|
await new Promise(resolve => waitForFiles(resolve))
|
|
547
|
+
delete mq.mobilettoHandlers[jobId]
|
|
548
|
+
delete mq.mobilettoErrorHandlers[jobId]
|
|
542
549
|
return files
|
|
543
550
|
}
|
|
544
551
|
|