Skip to content

Commit

Permalink
Make tracking and publishing schedules configurable (#1086)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ndpnt authored Jun 4, 2024
2 parents 4b6cf88 + 889fcc0 commit 1cc3e88
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 10 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,16 @@

All changes that impact users of this module are documented in this file, in the [Common Changelog](https://common-changelog.org) format with some additional specifications defined in the CONTRIBUTING file. This codebase adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## Unreleased [minor]

> Development of this release was supported by the [French Ministry for Foreign Affairs](https://www.diplomatie.gouv.fr/fr/politique-etrangere-de-la-france/diplomatie-numerique/) through its ministerial [State Startups incubator](https://beta.gouv.fr/startups/open-terms-archive.html) under the aegis of the Ambassador for Digital Affairs.
### Added

- Make tracking schedule configurable
- Make publishing schedule configurable
- Add tracking overrun protection

## 2.0.1 - 2024-05-31

_Full changeset and discussions: [#1085](https://github.com/OpenTermsArchive/engine/pull/1085)._
Expand Down
9 changes: 7 additions & 2 deletions bin/ota-dataset.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import './env.js';

import { program } from 'commander';
import config from 'config';
import cron from 'croner';
import cronstrue from 'cronstrue';

import { release } from '../scripts/dataset/index.js';
import logger from '../src/logger/index.js';
Expand All @@ -26,8 +28,11 @@ const options = {
if (!schedule) {
await release(options);
} else {
const trackingSchedule = config.get('@opentermsarchive/engine.dataset.publishingSchedule');
const humanReadableSchedule = cronstrue.toString(trackingSchedule);

logger.info('The scheduler is running…');
logger.info('Dataset will be published every Monday at 08:30 in the timezone of this machine');
logger.info(`Dataset will be published ${humanReadableSchedule.toLowerCase()} in the timezone of this machine`);

cron('30 8 * * MON', () => release(options));
cron(config.get('@opentermsarchive/engine.dataset.publishingSchedule'), () => release(options));
}
4 changes: 3 additions & 1 deletion config/default.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"@opentermsarchive/engine": {
"trackingSchedule": "30 */6 * * *",
"services": {
"declarationsPath": "./declarations"
},
Expand Down Expand Up @@ -57,7 +58,8 @@
},
"dataset": {
"title": "sandbox",
"versionsRepositoryURL": "https://github.com/OpenTermsArchive/sandbox"
"versionsRepositoryURL": "https://github.com/OpenTermsArchive/sandbox",
"publishingSchedule": "30 8 * * MON"
}
}
}
20 changes: 16 additions & 4 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
"chai-exclude": "^2.1.0",
"commander": "^9.4.1",
"config": "^3.3.6",
"croner": "^4.3.6",
"croner": "^8.0.2",
"cronstrue": "^2.50.0",
"cross-env": "^7.0.3",
"datauri": "^4.1.0",
"dotenv": "^10.0.0",
Expand Down
12 changes: 10 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import config from 'config';
import cron from 'croner';
import cronstrue from 'cronstrue';

import Archivist from './archivist/index.js';
import logger from './logger/index.js';
Expand Down Expand Up @@ -71,8 +72,15 @@ export default async function track({ services, types, extractOnly, schedule })
return;
}

const trackingSchedule = config.get('@opentermsarchive/engine.trackingSchedule');
const humanReadableSchedule = cronstrue.toString(trackingSchedule);

logger.info('The scheduler is running…');
logger.info('Terms will be tracked every six hours starting at half past midnight');
logger.info(`Terms will be tracked ${humanReadableSchedule.toLowerCase()} in the timezone of this machine`);

cron('30 */6 * * *', () => archivist.track({ services, types }));
cron(
trackingSchedule,
{ protect: job => logger.warn(`Tracking scheduled at ${new Date().toISOString()} were blocked by an unfinished tracking started at ${job.currentRun().toISOString()}`) },
() => archivist.track({ services, types }),
);
}

0 comments on commit 1cc3e88

Please sign in to comment.