debian-mirror-gitlab/app/assets/javascripts/jobs/mixins/delayed_job_mixin.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

54 lines
1.2 KiB
JavaScript
Raw Normal View History

2018-12-13 13:39:08 +05:30
import { calculateRemainingMilliseconds, formatTime } from '~/lib/utils/datetime_utility';
export default {
data() {
return {
remainingTime: formatTime(0),
remainingTimeIntervalId: null,
};
},
mounted() {
this.startRemainingTimeInterval();
},
beforeDestroy() {
if (this.remainingTimeIntervalId) {
clearInterval(this.remainingTimeIntervalId);
}
},
computed: {
isDelayedJob() {
2021-02-22 17:27:13 +05:30
return this.job?.scheduled || this.job?.scheduledAt;
},
scheduledTime() {
return this.job.scheduled_at || this.job.scheduledAt;
2018-12-13 13:39:08 +05:30
},
},
watch: {
isDelayedJob() {
this.startRemainingTimeInterval();
},
},
methods: {
startRemainingTimeInterval() {
if (this.remainingTimeIntervalId) {
clearInterval(this.remainingTimeIntervalId);
}
if (this.isDelayedJob) {
this.updateRemainingTime();
this.remainingTimeIntervalId = setInterval(() => this.updateRemainingTime(), 1000);
}
},
updateRemainingTime() {
2021-02-22 17:27:13 +05:30
const remainingMilliseconds = calculateRemainingMilliseconds(this.scheduledTime);
2018-12-13 13:39:08 +05:30
this.remainingTime = formatTime(remainingMilliseconds);
},
},
};