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

failed_jobs_list.vue « failure_widget « pipelines_list « components « pipelines « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 36687129cdd48a53a309bdff207534129e941c0f (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<script>
import { GlLoadingIcon } from '@gitlab/ui';
import { createAlert } from '~/alert';
import { __, s__, sprintf } from '~/locale';
import { getQueryHeaders } from '~/pipelines/components/graph/utils';
import getPipelineFailedJobs from '../../../graphql/queries/get_pipeline_failed_jobs.query.graphql';
import { graphqlEtagPipelinePath, sortJobsByStatus } from './utils';
import FailedJobDetails from './failed_job_details.vue';

const POLL_INTERVAL = 10000;

const JOB_ACTION_HEADER = __('Actions');
const JOB_ID_HEADER = __('Job ID');
const JOB_NAME_HEADER = __('Job name');
const STAGE_HEADER = __('Stage');

export default {
  components: {
    GlLoadingIcon,
    FailedJobDetails,
  },
  inject: ['fullPath', 'graphqlPath'],
  props: {
    isPipelineActive: {
      required: true,
      type: Boolean,
    },
    pipelineIid: {
      type: Number,
      required: true,
    },
  },
  data() {
    return {
      failedJobs: [],
      isActive: false,
      isLoadingMore: false,
    };
  },
  apollo: {
    failedJobs: {
      context() {
        return getQueryHeaders(this.graphqlResourceEtag);
      },
      query: getPipelineFailedJobs,
      pollInterval: POLL_INTERVAL,
      variables() {
        return {
          fullPath: this.fullPath,
          pipelineIid: this.pipelineIid,
        };
      },
      update(data) {
        const jobs = data?.project?.pipeline?.jobs?.nodes || [];
        return sortJobsByStatus(jobs);
      },
      result({ data }) {
        const pipeline = data?.project?.pipeline;

        if (pipeline?.jobs?.count) {
          this.$emit('failed-jobs-count', pipeline.jobs.count);
          this.isActive = pipeline.active;
        }
      },
      error(e) {
        createAlert({ message: e?.message || this.$options.i18n.fetchError, variant: 'danger' });
      },
    },
  },
  computed: {
    graphqlResourceEtag() {
      return graphqlEtagPipelinePath(this.graphqlPath, this.pipelineIid);
    },
    hasFailedJobs() {
      return this.failedJobs.length > 0;
    },
    isInitialLoading() {
      return this.isLoading && !this.isLoadingMore;
    },
    isLoading() {
      return this.$apollo.queries.failedJobs.loading;
    },
  },
  watch: {
    isPipelineActive(flag) {
      // Turn polling on and off based on REST actions
      // By refetching jobs, we will get the graphql `active`
      // field to update properly and cascade the polling changes
      this.refetchJobs();
      this.handlePolling(flag);
    },
    isActive(flag) {
      this.handlePolling(flag);
    },
  },
  mounted() {
    if (!this.isActive && !this.isPipelineActive) {
      this.handlePolling(false);
    }
  },
  methods: {
    handlePolling(isActive) {
      // If the pipeline status has changed and the widget is not expanded,
      // We start polling.
      if (isActive) {
        this.$apollo.queries.failedJobs.startPolling(POLL_INTERVAL);
      } else {
        this.$apollo.queries.failedJobs.stopPolling();
      }
    },
    async retryJob(jobName) {
      await this.refetchJobs();

      this.$toast.show(sprintf(this.$options.i18n.retriedJobsSuccess, { jobName }));
    },
    async refetchJobs() {
      this.isLoadingMore = true;

      try {
        await this.$apollo.queries.failedJobs.refetch();
      } catch {
        createAlert(this.$options.i18n.fetchError);
      } finally {
        this.isLoadingMore = false;
      }
    },
  },
  columns: [
    { text: JOB_NAME_HEADER, class: 'col-6' },
    { text: STAGE_HEADER, class: 'col-2' },
    { text: JOB_ID_HEADER, class: 'col-2' },
    { text: JOB_ACTION_HEADER, class: 'col-2' },
  ],
  i18n: {
    fetchError: __('There was a problem fetching failed jobs'),
    noFailedJobs: s__('Pipeline|No failed jobs in this pipeline 🎉'),
    retriedJobsSuccess: __('%{jobName} job is being retried'),
  },
};
</script>

<template>
  <div>
    <gl-loading-icon v-if="isInitialLoading" />
    <div v-else-if="!hasFailedJobs">{{ $options.i18n.noFailedJobs }}</div>
    <div v-else class="container-fluid gl-grid-tpl-rows-auto">
      <div class="row gl-mb-6 gl-text-gray-900">
        <div
          v-for="col in $options.columns"
          :key="col.text"
          class="gl-font-weight-bold gl-text-left"
          :class="col.class"
          data-testid="header"
        >
          {{ col.text }}
        </div>
      </div>
    </div>
    <failed-job-details
      v-for="job in failedJobs"
      :key="job.id"
      :job="job"
      @job-retried="retryJob"
    />
  </div>
</template>