mirror of
https://github.com/retorquere/zotero-better-bibtex.git
synced 2022-05-23 09:36:29 +03:00
queued worker
This commit is contained in:
@@ -19,6 +19,7 @@ import { flash } from './flash'
|
||||
import { $and, Query } from './db/loki'
|
||||
import { Events } from './events'
|
||||
import { Pinger } from './ping'
|
||||
import PQueue from 'p-queue'
|
||||
|
||||
import * as translatorMetadata from '../gen/translators.json'
|
||||
|
||||
@@ -40,6 +41,7 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint
|
||||
public byName: Record<string, Translator.Header>
|
||||
public byLabel: Record<string, Translator.Header>
|
||||
public itemType: { note: number, attachment: number, annotation: number }
|
||||
private queue: PQueue
|
||||
|
||||
public workers: { total: number, running: Set<number>, disabled: boolean, startup: number } = {
|
||||
total: 0,
|
||||
@@ -50,6 +52,11 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint
|
||||
|
||||
constructor() {
|
||||
Object.assign(this, translatorMetadata)
|
||||
this.queue = new PQueue({
|
||||
concurrency: 1,
|
||||
timeout: 1000 * 60 * 60, // eslint-disable-line no-magic-numbers
|
||||
throwOnTimeout: true,
|
||||
})
|
||||
}
|
||||
|
||||
public async init() {
|
||||
@@ -133,6 +140,10 @@ export const Translators = new class { // eslint-disable-line @typescript-eslint
|
||||
}
|
||||
|
||||
public async exportItemsByWorker(translatorID: string, displayOptions: Record<string, boolean>, job: ExportJob) {
|
||||
return this.queue.add(() => this.exportItemsByQueuedWorker(translatorID, displayOptions, job))
|
||||
}
|
||||
|
||||
private async exportItemsByQueuedWorker(translatorID: string, displayOptions: Record<string, boolean>, job: ExportJob) {
|
||||
if (job.path && job.canceled) return ''
|
||||
|
||||
await Zotero.BetterBibTeX.ready
|
||||
|
||||
41
package-lock.json
generated
41
package-lock.json
generated
@@ -27,6 +27,7 @@
|
||||
"kuromoji": "^0.1.2",
|
||||
"lodash": "^4.17.21",
|
||||
"ooooevan-jieba": "^1.0.3",
|
||||
"p-queue": "^7.2.0",
|
||||
"pako": "^2.0.4",
|
||||
"papaparse": "^5.3.2",
|
||||
"parse5": "^7.0.0",
|
||||
@@ -10086,6 +10087,32 @@
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/p-queue": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/p-queue/-/p-queue-7.2.0.tgz",
|
||||
"integrity": "sha512-Kvv7p13M46lTYLQ/PsZdaj/1Vj6u/8oiIJgyQyx4oVkOfHdd7M2EZvXigDvcsSzRwanCzQirV5bJPQFoSQt5MA==",
|
||||
"dependencies": {
|
||||
"eventemitter3": "^4.0.7",
|
||||
"p-timeout": "^5.0.2"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/p-timeout": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-5.0.2.tgz",
|
||||
"integrity": "sha512-sEmji9Yaq+Tw+STwsGAE56hf7gMy9p0tQfJojIAamB7WHJYJKf1qlsg9jqBWG8q9VCxKPhZaP/AcXwEoBcYQhQ==",
|
||||
"engines": {
|
||||
"node": ">=12"
|
||||
},
|
||||
"funding": {
|
||||
"url": "https://github.com/sponsors/sindresorhus"
|
||||
}
|
||||
},
|
||||
"node_modules/p-try": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz",
|
||||
@@ -23341,6 +23368,20 @@
|
||||
"p-limit": "^4.0.0"
|
||||
}
|
||||
},
|
||||
"p-queue": {
|
||||
"version": "7.2.0",
|
||||
"resolved": "https://registry.npmjs.org/p-queue/-/p-queue-7.2.0.tgz",
|
||||
"integrity": "sha512-Kvv7p13M46lTYLQ/PsZdaj/1Vj6u/8oiIJgyQyx4oVkOfHdd7M2EZvXigDvcsSzRwanCzQirV5bJPQFoSQt5MA==",
|
||||
"requires": {
|
||||
"eventemitter3": "^4.0.7",
|
||||
"p-timeout": "^5.0.2"
|
||||
}
|
||||
},
|
||||
"p-timeout": {
|
||||
"version": "5.0.2",
|
||||
"resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-5.0.2.tgz",
|
||||
"integrity": "sha512-sEmji9Yaq+Tw+STwsGAE56hf7gMy9p0tQfJojIAamB7WHJYJKf1qlsg9jqBWG8q9VCxKPhZaP/AcXwEoBcYQhQ=="
|
||||
},
|
||||
"p-try": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/p-try/-/p-try-1.0.0.tgz",
|
||||
|
||||
@@ -75,6 +75,7 @@
|
||||
"kuromoji": "^0.1.2",
|
||||
"lodash": "^4.17.21",
|
||||
"ooooevan-jieba": "^1.0.3",
|
||||
"p-queue": "^7.2.0",
|
||||
"pako": "^2.0.4",
|
||||
"papaparse": "^5.3.2",
|
||||
"parse5": "^7.0.0",
|
||||
|
||||
4
typings/translators.d.ts
vendored
4
typings/translators.d.ts
vendored
@@ -2,6 +2,7 @@ import { Item, Attachment, Collection, Tag } from '../gen/typings/serialized-ite
|
||||
|
||||
export namespace Translators {
|
||||
namespace Worker {
|
||||
/*
|
||||
type Environment = {
|
||||
version: string
|
||||
platform: string
|
||||
@@ -23,8 +24,8 @@ export namespace Translators {
|
||||
cache: Record<number, {itemID: number, reference: string, metadata: any, meta: { updated: number }}>
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
type Config = {
|
||||
preferences: any,
|
||||
options: any,
|
||||
@@ -43,7 +44,6 @@ export namespace Translators {
|
||||
worker: number
|
||||
},
|
||||
}
|
||||
*/
|
||||
|
||||
type Message =
|
||||
{ kind: 'configure', config: Environment }
|
||||
|
||||
Reference in New Issue
Block a user