+export const getProcessRuntime = ({ container }: Process) => {
+ if (container) {
+ if (container.startedAt === null) {
+ return 0;
+ }
+ if (container.finishedAt === null) {
+ // Count it from now
+ return new Date().getTime() - new Date(container.startedAt).getTime();
+ }
+ return getTimeDiff(container.finishedAt, container.startedAt);
+ } else {
+ return 0;
+ }
+};
+
+
+export const getProcessStatusStyles = (status: string, theme: ArvadosTheme): React.CSSProperties => {
+ let color = theme.customs.colors.grey500;
+ let running = false;
+ switch (status) {
+ case ProcessStatus.RUNNING:
+ color = theme.customs.colors.green800;
+ running = true;
+ break;
+ case ProcessStatus.COMPLETED:
+ color = theme.customs.colors.green800;
+ break;
+ case ProcessStatus.WARNING:
+ color = theme.customs.colors.green800;
+ running = true;
+ break;
+ case ProcessStatus.FAILING:
+ color = theme.customs.colors.red900;
+ running = true;
+ break;
+ case ProcessStatus.CANCELLED:
+ case ProcessStatus.FAILED:
+ color = theme.customs.colors.red900;
+ break;
+ case ProcessStatus.QUEUED:
+ color = theme.customs.colors.grey600;
+ running = true;
+ break;
+ default:
+ color = theme.customs.colors.grey600;
+ break;
+ }
+
+ // Using color and running we build the text, border, and background style properties
+ return {
+ // Set background color when not running, otherwise use white
+ backgroundColor: running ? theme.palette.common.white : color,
+ // Set text color to status color when running, else use white text for solid button
+ color: running ? color : theme.palette.common.white,
+ // Set border color when running, else omit the style entirely
+ ...(running ? {border: `2px solid ${color}`} : {}),
+ };
+};
+
+export const getProcessStatus = ({ containerRequest, container }: Process): ProcessStatus => {
+ switch (true) {
+ case containerRequest.containerUuid && !container:
+ return ProcessStatus.UNKNOWN;
+
+ case containerRequest.state === ContainerRequestState.FINAL &&
+ container?.state !== ContainerState.COMPLETE:
+ // Request was finalized before its container started (or the
+ // container was cancelled)
+ return ProcessStatus.CANCELLED;
+
+ case containerRequest.state === ContainerRequestState.UNCOMMITTED:
+ return ProcessStatus.DRAFT;
+
+ case container?.state === ContainerState.COMPLETE:
+ if (container?.exitCode === 0) {
+ return ProcessStatus.COMPLETED;
+ }
+ return ProcessStatus.FAILED;
+
+ case container?.state === ContainerState.CANCELLED:
+ return ProcessStatus.CANCELLED;
+
+ case container?.state === ContainerState.QUEUED ||
+ container?.state === ContainerState.LOCKED:
+ if (containerRequest.priority === 0) {
+ return ProcessStatus.ONHOLD;
+ }
+ return ProcessStatus.QUEUED;
+
+ case container?.state === ContainerState.RUNNING:
+ if (!!container?.runtimeStatus.error) {
+ return ProcessStatus.FAILING;
+ }
+ if (!!container?.runtimeStatus.warning) {
+ return ProcessStatus.WARNING;
+ }
+ return ProcessStatus.RUNNING;
+
+ default:
+ return ProcessStatus.UNKNOWN;
+ }
+};