Skip to content

Commit

Permalink
Merge pull request #44 from openactive/3-spider-errors
Browse files Browse the repository at this point in the history
spider: Write errors to database
  • Loading branch information
odscjames authored Jun 26, 2020
2 parents e15deb3 + 354e7ac commit 31d5016
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 0 deletions.
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
);
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

0 comments on commit 31d5016

Please sign in to comment.