diff --git a/app/services/publish.js b/app/services/publish.js index f7ecff1d3..5f19d3393 100644 --- a/app/services/publish.js +++ b/app/services/publish.js @@ -1,5 +1,5 @@ import Service, { inject as service } from '@ember/service'; -import { task, all } from 'ember-concurrency'; +import { task, all, timeout } from 'ember-concurrency'; import { tracked } from '@glimmer/tracking'; export class Extract { @@ -57,7 +57,7 @@ export default class PublishService extends Service { @task *_loadExtractsTask(meetingId) { const [newExtracts, meeting, treatments, versionedTreatments] = yield all([ - fetch(`/prepublish/behandelingen/${meetingId}`).then((res) => res.json()), + this.pollForPrepublisherResults(meetingId), this.store.findRecord('zitting', meetingId), this.store.query('behandeling-van-agendapunt', { 'filter[onderwerp][zitting][:id:]': meetingId, @@ -116,4 +116,23 @@ export default class PublishService extends Service { } this.treatmentExtractsMap = extractMap; } + + async pollForPrepublisherResults(meetingId) { + let uuidResp = await fetch(`/prepublish/behandelingen/${meetingId}`); + let jobId = (await uuidResp.json()).data.attributes.jobId; + + let maxIterations = 600; + let resp; + do { + await timeout(1000); + resp = await fetch(`/prepublish/job-result/${jobId}`); + maxIterations--; + } while (resp.status === 404 && maxIterations > 0); + + if (resp.status !== 200) { + throw new Error(await resp.text()); + } else { + return await resp.json(); + } + } }