Skip to content

Commit

Permalink
More skip options, fixes OpenTermsArchive#1103
Browse files Browse the repository at this point in the history
  • Loading branch information
michielbdejong committed Sep 13, 2024
1 parent 5963f72 commit f1c5c97
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 9 deletions.
5 changes: 4 additions & 1 deletion bin/ota-track.js
Original file line number Diff line number Diff line change
Expand Up @@ -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());
10 changes: 7 additions & 3 deletions src/archivist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 7 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
});
Expand All @@ -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;
}

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f1c5c97

Please sign in to comment.