From a21979735197a28d230bd05907a047c9e1ce20d7 Mon Sep 17 00:00:00 2001 From: Michiel de Jong Date: Fri, 13 Sep 2024 16:43:50 +0200 Subject: [PATCH] More skip options, fixes #1103 --- bin/ota-track.js | 5 ++++- src/archivist/index.js | 14 +++++++++----- src/index.js | 12 +++++++----- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/bin/ota-track.js b/bin/ota-track.js index 77e480ac5..40745362a 100755 --- a/bin/ota-track.js +++ b/bin/ota-track.js @@ -16,6 +16,9 @@ program .option('-s, --services [serviceId...]', 'service IDs of services to track') .option('-t, --types [termsType...]', 'terms types to track') .option('-e, --extract-only', 'extract versions from existing snapshots with latest declarations and engine, without recording new snapshots') - .option('--schedule', 'track automatically at a regular interval'); + .option('--schedule', 'track automatically at a regular interval') + .option('--skipPreRun', 'skip the pre run') + .option('--skipReadBack', 'skip the read-back of snapshots') + .option('--skipSnapshots', 'skip both the writing and the read-back of the snapshots'); track(program.parse(process.argv).opts()); diff --git a/src/archivist/index.js b/src/archivist/index.js index e69ede836..e48fb163e 100644 --- a/src/archivist/index.js +++ b/src/archivist/index.js @@ -99,7 +99,7 @@ export default class Archivist extends events.EventEmitter { }); } - async track({ services: servicesIds = this.servicesIds, types: termsTypes = [], extractOnly = false } = {}) { + async track({ services: servicesIds = this.servicesIds, types: termsTypes = [], extractOnly = false, skipSnapshots = false, skipReadBack = false } = {}) { const numberOfTerms = Service.getNumberOfTerms(this.services, servicesIds, termsTypes); this.emit('trackingStarted', servicesIds.length, numberOfTerms, extractOnly); @@ -114,7 +114,7 @@ export default class Archivist extends events.EventEmitter { return; } - this.trackingQueue.push({ terms: this.services[serviceId].getTerms({ type: termsType }), extractOnly }); + this.trackingQueue.push({ terms: this.services[serviceId].getTerms({ type: termsType }), extractOnly, skipSnapshots, skipReadBack }); }); }); @@ -127,13 +127,17 @@ export default class Archivist extends events.EventEmitter { this.emit('trackingCompleted', servicesIds.length, numberOfTerms, extractOnly); } - async trackTermsChanges({ terms, extractOnly = false }) { + async trackTermsChanges({ terms, extractOnly = false, skipReadBack = false, skipSnapshots = false }) { if (!extractOnly) { await this.fetchSourceDocuments(terms); - await this.recordSnapshots(terms); + if (!skipSnapshots) { + await this.recordSnapshots(terms); + } } - await this.loadSourceDocumentsFromSnapshots(terms); + if (!skipSnapshots && !skipReadBack) { + await this.loadSourceDocumentsFromSnapshots(terms); + } if (terms.sourceDocuments.filter(sourceDocument => !sourceDocument.content).length) { // If some source documents do not have associated snapshots, it is not possible to generate a fully valid version diff --git a/src/index.js b/src/index.js index 2083e1802..2f33fcf63 100644 --- a/src/index.js +++ b/src/index.js @@ -11,8 +11,8 @@ import Reporter from './reporter/index.js'; const require = createRequire(import.meta.url); -export default async function track({ services, types, extractOnly, schedule }) { - const archivist = new Archivist({ +export default async function track({ services, types, extractOnly, skipPreRun, skipSnapshots, skipReadBack, schedule }) { + const archivist = new Archivist({ recorderConfig: config.get('@opentermsarchive/engine.recorder'), fetcherConfig: config.get('@opentermsarchive/engine.fetcher'), }); @@ -39,9 +39,11 @@ export default async function track({ services, types, extractOnly, schedule }) // The result of the extraction step that generates the version from the snapshots may depend on changes to the engine or its dependencies. // The process thus starts by only performing the extraction process so that any version following such changes can be labelled (to avoid sending notifications, for example) - await archivist.track({ services, types, extractOnly: true }); + if (!skipPreRun) { + await archivist.track({ services, types, extractOnly: true, skipSnapshots }); + } - if (extractOnly) { + if (extractOnly && !skipPreRun) { return; } @@ -73,7 +75,7 @@ export default async function track({ services, types, extractOnly, schedule }) } if (!schedule) { - await archivist.track({ services, types }); + await archivist.track({ services, types, extractOnly, skipSnapshots, skipReadBack }); return; }