Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Extend crawler logging #834

Merged
merged 1 commit into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ export default {
coverageReporters: ['json-summary', 'text'],
coverageThreshold: {
global: {
lines: 71.6,
statements: 71.63,
lines: 71.8,
statements: 71.83,
branches: 63.3,
functions: 69.72,
},
Expand Down
9 changes: 8 additions & 1 deletion src/crawler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export class Crawler {
const registrations =
await this.registrationStore.findRegistrationsReadBefore(dateLastRead);
for (const registration of registrations) {
this.logger.info(`Crawling registration URL ${registration.url}`);
this.logger.info(`Crawling registration URL ${registration.url}...`);
let datasets: DatasetExt[] = [];
let statusCode = 200;
let isValid = false;
Expand All @@ -33,21 +33,28 @@ export class Crawler {
const validationResult = await this.validator.validate(data);
isValid = validationResult.state === 'valid';
if (isValid) {
this.logger.info(`${registration.url} passes validation`);
datasets = await fetch(registration.url);
await this.datasetStore.store(datasets);
datasets.map(async dataset => {
const dcatValidationResult = await this.validator.validate(dataset);
const rating = rate(dcatValidationResult as Valid);
await this.ratingStore.store(extractIri(dataset), rating);
});
} else {
this.logger.info(`${registration.url} does not pass validation`);
}
} catch (e) {
if (e instanceof HttpError) {
statusCode = e.statusCode;
this.logger.info(
`${registration.url} returned HTTP error ${statusCode}`
);
}

if (e instanceof NoDatasetFoundAtUrl) {
// Request was successful, but no datasets exist any longer at the URL.
this.logger.info(`${registration.url} has no datasets`);
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/graphdb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ export class GraphDbRegistrationStore implements RegistrationStore {

constructor(private client: GraphDbClient) {}

async store(registration: Registration) {
async store(registration: Registration): Promise<void> {
const quads = [
this.registrationQuad(
registration,
Expand Down Expand Up @@ -268,7 +268,7 @@ export class GraphDbRegistrationStore implements RegistrationStore {
url: '/statements',
body: result,
});
resolve(null);
resolve();
} catch (e) {
reject(e);
}
Expand Down
2 changes: 1 addition & 1 deletion src/registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export interface RegistrationStore {
/**
* Store a {@see Registration}, replacing any Registrations with the same URL.
*/
store(registration: Registration): void;
store(registration: Registration): Promise<void>;
findRegistrationsReadBefore(date: Date): Promise<Registration[]>;
}

Expand Down
2 changes: 1 addition & 1 deletion test/mock.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class MockRegistrationStore implements RegistrationStore {
);
}

store(registration: Registration): void {
async store(registration: Registration): Promise<void> {
this.registrations.set(registration.url, registration);
}
}
Expand Down