Welcome to mirror list, hosted at ThFree Co, Russian Federation.

status_poller.js « services « import_groups « import_entities « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 6ad5e448a40bebcf22d6c10e81b5b13deacad4f7 (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 { createAlert } 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: () =>
        createAlert({
          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();
  }
}