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

spider: Write errors to database #44

Merged
merged 1 commit into from
Jun 26, 2020
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
CREATE TABLE spider_data_catalog_error (
url TEXT NOT NULL,
error TEXT NOT NULL,
error_at TIMESTAMP WITHOUT TIME ZONE NOT NULL default (now() at time zone 'utc'),
found_via JSON NOT NULL
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't we want a fk here to the publisher?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because it might be an error at the level of getting a data catalogue, and at that point there is no publisher. Also even an error when parsing a publisher would result in no publisher being written.

);
1 change: 1 addition & 0 deletions src/lib/database.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ async function delete_database() {
var client;
try {
client = await database_pool.connect();
await client.query('DROP TABLE IF EXISTS spider_data_catalog_error CASCADE');
await client.query('DROP TABLE IF EXISTS normalised_data CASCADE');
await client.query('DROP TABLE IF EXISTS raw_data CASCADE');
await client.query('DROP TABLE IF EXISTS publisher_feed CASCADE');
Expand Down
19 changes: 19 additions & 0 deletions src/lib/spider.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ async function spider_data_catalog(url, url_history) {
console.error(url_history);
console.error(url);
console.error(error);
spider_data_catalog_error(url, error, url_history)
}

}
Expand Down Expand Up @@ -82,6 +83,7 @@ async function spider_data_set(url, url_history) {
console.error(url_history);
console.error(url);
console.error(error);
spider_data_catalog_error(url, error, url_history)
}
}

Expand Down Expand Up @@ -132,6 +134,23 @@ async function write_publisher(data) {

};

async function spider_data_catalog_error(url, error, found_via) {
const client = await database_pool.connect();
try {
await client.query(
'INSERT INTO spider_data_catalog_error (url, error, found_via) VALUES ($1, $2, $3)',
[url, error, {"trail":found_via}]
);
} catch(error) {
console.error("ERROR spider_data_catalog_error");
console.error(error);
} finally {
// Make sure to release the client before any error handling,
// just in case the error handling itself throws an error.
client.release()
}
}

export {
spider,
spider_data_catalog,
Expand Down