Skip to content

Commit

Permalink
Merge branch 'master' into development
Browse files Browse the repository at this point in the history
  • Loading branch information
abeforgit committed Aug 18, 2021
2 parents ecfd937 + 17922fe commit 80c6d73
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions app/services/publish.js
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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();
}
}
}

0 comments on commit 80c6d73

Please sign in to comment.