1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import { ContainerRequestResource } from '../../models/container-request';
6 import { ContainerResource } from '../../models/container';
7 import { ResourcesState, getResource } from '~/store/resources/resources';
8 import { filterResources } from '../resources/resources';
9 import { ResourceKind, Resource } from '~/models/resource';
10 import { getDiffTime } from '~/common/formatters';
12 export interface Process {
13 containerRequest: ContainerRequestResource;
14 container?: ContainerResource;
17 export const getProcess = (uuid: string) => (resources: ResourcesState): Process | undefined => {
18 const containerRequest = getResource<ContainerRequestResource>(uuid)(resources);
19 if (containerRequest) {
20 if (containerRequest.containerUuid) {
21 const container = getResource<ContainerResource>(containerRequest.containerUuid)(resources);
23 return { containerRequest, container };
26 return { containerRequest };
31 export const getSubprocesses = (uuid: string) => (resources: ResourcesState) => {
32 const process = getProcess(uuid)(resources);
33 if (process && process.container) {
34 const containerRequests = filterResources(isSubprocess(process.container.uuid))(resources) as ContainerRequestResource[];
35 return containerRequests.reduce((subprocesses, { uuid }) => {
36 const process = getProcess(uuid)(resources);
38 ? [...subprocesses, process]
45 export const getProcessRuntime = (subprocess: Process) =>
47 ? getDiffTime(subprocess.container.finishedAt || '', subprocess.container.startedAt || '')
50 export const getProcessStatus = (process: Process) =>
52 ? process.container.state
53 : process.containerRequest.state;
55 const isSubprocess = (containerUuid: string) => (resource: Resource) =>
56 resource.kind === ResourceKind.CONTAINER_REQUEST
57 && (resource as ContainerRequestResource).requestingContainerUuid === containerUuid;