github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/pkg/ui/src/views/jobs/duration.tsx (about) 1 // Copyright 2018 The Cockroach Authors. 2 // 3 // Use of this software is governed by the Business Source License 4 // included in the file licenses/BSL.txt. 5 // 6 // As of the Change Date specified in that file, in accordance with 7 // the Business Source License, use of this software will be governed 8 // by the Apache License, Version 2.0, included in the file 9 // licenses/APL.txt. 10 11 import React from "react"; 12 import {TimestampToMoment} from "src/util/convert"; 13 import { 14 JOB_STATUS_PENDING, 15 JOB_STATUS_RUNNING, JOB_STATUS_SUCCEEDED, 16 jobHasOneOfStatuses, 17 } from "src/views/jobs/jobStatusOptions"; 18 import { 19 formatDuration, 20 21 } from "src/views/jobs/index"; 22 import _ from "lodash"; 23 import moment from "moment"; 24 import Job = cockroach.server.serverpb.JobsResponse.IJob; 25 import {cockroach} from "src/js/protos"; 26 27 export class Duration extends React.PureComponent<{ job: Job }> { 28 render() { 29 const started = TimestampToMoment(this.props.job.started); 30 const finished = TimestampToMoment(this.props.job.finished); 31 const modified = TimestampToMoment(this.props.job.modified); 32 if (jobHasOneOfStatuses(this.props.job, JOB_STATUS_PENDING)) { 33 return "Waiting for GG TCL"; 34 } else if (jobHasOneOfStatuses(this.props.job, JOB_STATUS_RUNNING)) { 35 const fractionCompleted = this.props.job.fraction_completed; 36 if (fractionCompleted > 0) { 37 const duration = modified.diff(started); 38 const remaining = duration / fractionCompleted - duration; 39 return <span 40 className="jobs-table__duration--right">{formatDuration(moment.duration(remaining)) + " remaining"}</span>; 41 } 42 } else if (jobHasOneOfStatuses(this.props.job, JOB_STATUS_SUCCEEDED)) { 43 return "Duration: " + formatDuration(moment.duration(finished.diff(started))); 44 } 45 return null; 46 } 47 }