-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LMB-339: add cronjob that fetches the efffectieve mandatarissen every…
… minute
- Loading branch information
1 parent
6630ed3
commit 7a6b165
Showing
4 changed files
with
76 additions
and
17 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
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,49 @@ | ||
import { CronJob } from 'cron'; | ||
|
||
import { querySudo } from '@lblod/mu-auth-sudo'; | ||
import { getSparqlResults } from '../util/sparql-result'; | ||
|
||
const NOTIFICATION_CRON_PATTERN = '* * * * *'; | ||
let running = false; | ||
|
||
export const cronjob = CronJob.from({ | ||
cronTime: NOTIFICATION_CRON_PATTERN, | ||
onTick: async () => { | ||
if (running) { | ||
return; | ||
} | ||
running = true; | ||
await HandleEffectieveMandatarissen(); | ||
running = false; | ||
}, | ||
}); | ||
|
||
async function HandleEffectieveMandatarissen() { | ||
await fetchMandatarissen(); | ||
running = false; | ||
} | ||
|
||
async function fetchMandatarissen() { | ||
const query = ` | ||
PREFIX mandaat: <http://data.vlaanderen.be/ns/mandaat#> | ||
SELECT DISTINCT ?mandataris | ||
WHERE { | ||
GRAPH ?graph { | ||
?mandataris a mandaat:Mandataris; | ||
mandaat:status <http://data.vlaanderen.be/id/concept/MandatarisStatusCode/21063a5b-912c-4241-841c-cc7fb3c73e75>. | ||
} | ||
FILTER NOT EXISTS { | ||
?graph a <http://mu.semte.ch/vocabularies/ext/FormHistory> | ||
} | ||
FILTER NOT EXISTS { | ||
?graph a <http://mu.semte.ch/graphs/public> | ||
} | ||
} | ||
`; | ||
|
||
const sparqlResult = await querySudo(query); | ||
const results = getSparqlResults(sparqlResult); | ||
|
||
console.log('LOG: results', results.length); | ||
} |
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