Skip to content

Commit

Permalink
Merge pull request #34 from openactive/22-settings
Browse files Browse the repository at this point in the history
validate: loadRemoteJson and remoteJsonCachePath options
  • Loading branch information
odscjames authored Jun 24, 2020
2 parents 1b6ea0d + 6eb2a38 commit 5dc304d
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/dataModelValidatorRemoteJsonCache
5 changes: 5 additions & 0 deletions src/lib/settings.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import path from 'path';

const Settings = {
"spiderDataCatalogStartURL": process.env.SPIDER_DATA_CATALOG_START_URL || 'https://www.openactive.io/data-catalogs/data-catalog-collection.jsonld',

Expand All @@ -15,6 +17,9 @@ const Settings = {
"sleepWhileSpiderDataCatalogSeconds": 1,
"sleepWhileDownloadRawSeconds": 1,

// this is in cwd() and not /tmp so it works well on Heroku
"dataModelValidatorRemoteJsonCachePath": path.join(process.cwd(), 'dataModelValidatorRemoteJsonCache'),

}

export default Settings;
17 changes: 16 additions & 1 deletion src/lib/validate-raw-data.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,27 @@
import { database_pool } from './database.js';
import validator from '@openactive/data-model-validator';
import Settings from './settings.js';
import fs from 'fs';

const validate_options = {
loadRemoteJson: true,
remoteJsonCachePath: Settings.dataModelValidatorRemoteJsonCachePath,
};

async function set_up_for_validation() {
if (!fs.existsSync(validate_options.remoteJsonCachePath)) {
await fs.promises.mkdir(validate_options.remoteJsonCachePath, {recursive:true});
}
}

/*
* TODO This will run only one check at a time - add something so it runs several at once!
* But I want to discuss with others best way to do that first
*/
async function validate_raw_data_all() {

await set_up_for_validation();

const client = await database_pool.connect();
try {
while(true) {
Expand All @@ -31,7 +46,7 @@ async function validate_raw_data_all() {

async function validate_raw_data(raw_data) {

const result = await validator.validate(raw_data.data);
const result = await validator.validate(raw_data.data, validate_options);
const result_filtered = result.filter(r => r.severity === "failure");

const client = await database_pool.connect();
Expand Down

0 comments on commit 5dc304d

Please sign in to comment.