blob: ba0f2bb947ae609a2921a6c9010393639b8fd8eb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
|
import Visibility from 'visibilityjs';
import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils';
import Poll from '~/lib/utils/poll';
import { s__ } from '~/locale';
export class StatusPoller {
constructor({ updateImportStatus, pollPath }) {
this.eTagPoll = new Poll({
resource: {
fetchJobs: () => axios.get(pollPath),
},
method: 'fetchJobs',
successCallback: ({ data: statuses }) => {
statuses.forEach((status) => updateImportStatus(status));
},
errorCallback: () =>
createFlash({
message: s__('BulkImport|Update of import statuses with realtime changes failed'),
}),
});
Visibility.change(() => {
if (!Visibility.hidden()) {
this.eTagPoll.restart();
} else {
this.eTagPoll.stop();
}
});
}
startPolling() {
this.eTagPoll.makeRequest();
}
stopPolling() {
this.eTagPoll.stop();
}
}
|