-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from oliviervd/master
v 0.1 resolver
- Loading branch information
Showing
12 changed files
with
263 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.env |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import {supabase} from "./supabaseClient.js"; | ||
export async function connectorObjects() { | ||
const {data, error} = await supabase | ||
.from('dmg_objects_LDES') | ||
.select('objectNumber, RESOLVES_TO, PURI, iiif_manifest, LDES_raw') | ||
return data; | ||
} | ||
|
||
export async function writeIIIFSTATUS(_on, RES) { | ||
const {data, error} = await supabase | ||
.from('dmg_objects_LDES') | ||
.update({'iiif_manifest_RESPONSE': RES}) | ||
.eq("objectNumber", _on) | ||
} | ||
|
||
export async function writePURI(_on, PURI) { | ||
const{data, error} = await supabase | ||
.from('dmg_objects_LDES') | ||
.update({'PURI': PURI}) | ||
.eq("objectNumber", _on) | ||
} | ||
|
||
export async function writeSTATUS(_on, STATUS) { | ||
const {data, error} = await supabase | ||
.from('dmg_objects_LDES') | ||
.update({'STATUS':STATUS}) | ||
.eq("objectNumber", _on) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import {createClient} from "@supabase/supabase-js"; | ||
import * as dotenv from 'dotenv' | ||
|
||
// init dotenv | ||
dotenv.config() | ||
|
||
const SUPABASE_URL = process.env.SUPABASE_URL | ||
const SUPABASE_KEY = process.env.SUPABASE_KEY | ||
|
||
export const supabase = createClient(SUPABASE_URL, SUPABASE_KEY) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
import {monitorHealthUpstream} from "./utils/tests.js"; | ||
|
||
function main() { | ||
console.log("---------------------") | ||
console.log("BOOTING UP HEALTH CHECK - RESOLVER") | ||
console.log("---------------------") | ||
|
||
// CHECK RECORDS | ||
monitorHealthUpstream(); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# RESOLVER - DESIGN MUSEUM GENT | ||
Node-based service to maintain a healthy upstream for the [REST-API](https://github.com/oliviervd/dmg-rest-api) of Design Museum Gent. | ||
|
||
The service checks the museums database and REST-API on a weekly basis and based on a switch-case assigns it a status of HEALTHY or UNHEALTHY. This output is written away in a report and send to staff members within the museum for follow-up. | ||
|
||
This way we want to ensure persistent URIs. | ||
|
||
### output: | ||
|
||
``` | ||
---------- | ||
0/5864 | ||
checking: https://data.designmuseumgent.be/id/object/0559 | ||
IIIF Manifest Response: 200 | ||
objectnumber in LDES: 0559 | ||
content in LDES matches with PID | ||
STATUS: HEALTHY | ||
---------- | ||
1/5864 | ||
checking: https://data.designmuseumgent.be/id/object/2017-0448 | ||
IIIF Manifest Response: 200 | ||
objectnumber in LDES: 2017-0448 | ||
content in LDES matches with PID | ||
STATUS: HEALTHY | ||
---------- | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
import {connectorObjects, writeIIIFSTATUS, writePURI, writeSTATUS} from "../client/client.js"; | ||
import * as dotenv from 'dotenv' | ||
|
||
// init dotenv | ||
dotenv.config() | ||
|
||
const baseURI = process.env._baseURI | ||
|
||
function sleep(ms){ | ||
return new Promise(resolve=>setTimeout(resolve, ms)) | ||
} | ||
|
||
export async function monitorHealthUpstream() { | ||
// this function checks the health of the published data and defines rerouting if necessary. | ||
|
||
let _stream = await connectorObjects() | ||
let _total = _stream.length | ||
let _count = 0; | ||
for (let i=0; i < _stream.length; i++) { | ||
|
||
let statusManifest; | ||
let statusLDES; | ||
|
||
// define PID and write to DB if not yet in there. | ||
const PURI = baseURI + `id/object/${_stream[i]["objectNumber"]}` | ||
console.log("----------") | ||
console.log(`${i}/${_total}`) | ||
console.log(`checking: ${PURI}`) | ||
|
||
|
||
// 1. check LDES - (see if it aligns with PID) | ||
statusLDES = checkLDES(_stream[i]["objectNumber"], _stream[i]["LDES_raw"]) | ||
|
||
// SWITCH A | ||
// 2. if this first check passes. | ||
if(statusLDES){ | ||
// 3A. check status manifest (response request) | ||
// SWITCH B | ||
statusManifest = checkManifest(_stream[i]["iiif_manifest"], _stream[i]["objectNumber"]) | ||
await sleep(1000); | ||
console.log("STATUS: HEALTHY") | ||
} | ||
|
||
// 3B. if this first check does not pass: | ||
else { | ||
// write: STATUS = UNHEALTHY (needs follow-up) | ||
writeSTATUS(_stream[i]["objectNumber"], "UNHEALTHY") | ||
console.log("STATUS: UNHEALTHY") | ||
} | ||
|
||
|
||
|
||
// 2. write PURI to DB | ||
writePURI(_stream[i]["objectNumber"], PURI) | ||
|
||
// 3. write route to resolve to to DB | ||
|
||
await sleep(3000); | ||
|
||
} | ||
} | ||
|
||
function defineStatus(RES_MANIFEST, RES_LDES){ | ||
|
||
} | ||
|
||
function checkLDES(_on, LDES) { | ||
// function that checks if the content alligns with the PID | ||
// input: objectnumber (derived from PID) | ||
|
||
let _STATUS; | ||
|
||
const _onLDES = extractObjectNumberLDES(LDES) | ||
if (_onLDES === _on) { | ||
console.log("content in LDES matches with PID") | ||
_STATUS = true; | ||
} else { | ||
console.log("WARNING: CONTENT DOES NOT MATCH.") | ||
_STATUS = false | ||
} | ||
return _STATUS | ||
} | ||
|
||
function extractObjectNumberLDES(LDES) { | ||
const LDES_ON = LDES['object']['http://www.w3.org/ns/adms#identifier'][1]['skos:notation']['@value'] | ||
console.log(`objectnumber in LDES: ${LDES_ON}`) | ||
return LDES_ON | ||
} | ||
|
||
export async function checkManifest(manifest, _ON){ | ||
let _STATUS; | ||
// fetch data upstream (db) | ||
fetch(manifest) | ||
.then((res) => { | ||
//console.log(res.status) | ||
console.log(`IIIF Manifest Response: ${res.status}`) | ||
_STATUS = checkResponse(res.status, _ON) | ||
|
||
}) | ||
.catch((err) => { | ||
console.log(err) | ||
}) | ||
return _STATUS; | ||
} | ||
|
||
function checkResponse(RES, _ON) { | ||
// check response and write to DB. | ||
// column: iiif_manifest_RESPONSE | ||
let STAT; | ||
switch(RES) { | ||
case RES=200: | ||
// OK | ||
writeIIIFSTATUS(_ON, RES) | ||
writeSTATUS(_ON, "HEALTHY") | ||
STAT = true; | ||
|
||
case RES=403: | ||
// FORBIDDEN (restricted access) | ||
writeIIIFSTATUS(_ON, RES) | ||
writeSTATUS(_ON, "HEALTHY") | ||
STAT = true; | ||
|
||
case RES=404: | ||
// NOT FOUND | ||
writeIIIFSTATUS(_ON, RES) | ||
writeSTATUS(_ON, "UNHEALTHY") | ||
STAT = false; | ||
|
||
case RES=503: | ||
// SERVICE UNAVAILABLE | ||
writeIIIFSTATUS(_ON, RES) | ||
STAT = false; | ||
} | ||
return STAT; | ||
} | ||
|