Skip to content

Commit 3804367

Browse files
committed
chore: use an inteface for container listing options
1 parent a82a9b8 commit 3804367

File tree

2 files changed

+12
-7
lines changed

2 files changed

+12
-7
lines changed

api/src/core/modules/docker/get-docker-containers.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import fs from 'fs';
22

33
import camelCaseKeys from 'camelcase-keys';
4-
import { ContainerInfo } from 'dockerode';
54

65
import type { ContainerPort, Docker, DockerContainer } from '@app/graphql/generated/api/types.js';
76
import { dockerLogger } from '@app/core/log.js';
@@ -11,13 +10,16 @@ import { ContainerPortType, ContainerState } from '@app/graphql/generated/api/ty
1110
import { getters, store } from '@app/store/index.js';
1211
import { updateDockerState } from '@app/store/modules/docker.js';
1312

13+
export interface ContainerListingOptions {
14+
useCache?: boolean;
15+
}
16+
1417
/**
1518
* Get all Docker containers.
1619
* @returns All the in/active Docker containers on the system.
1720
*/
18-
1921
export const getDockerContainers = async (
20-
{ useCache } = { useCache: true }
22+
{ useCache }: ContainerListingOptions = { useCache: true }
2123
): Promise<Array<DockerContainer>> => {
2224
const dockerState = getters.docker();
2325
if (useCache && dockerState.containers) {

api/src/unraid-api/graph/resolvers/docker/docker.service.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,22 @@
11
import { Injectable } from '@nestjs/common';
22

33
import type { DockerContainer } from '@app/graphql/generated/api/types.js';
4-
import { getDockerContainers } from '@app/core/modules/docker/get-docker-containers.js';
4+
import {
5+
ContainerListingOptions,
6+
getDockerContainers,
7+
} from '@app/core/modules/docker/get-docker-containers.js';
58
import { docker } from '@app/core/utils/clients/docker.js';
69

710
@Injectable()
811
export class DockerService {
9-
public async getContainers(useCache = false): Promise<DockerContainer[]> {
12+
public async getContainers({ useCache }: ContainerListingOptions): Promise<DockerContainer[]> {
1013
return getDockerContainers({ useCache });
1114
}
1215

1316
public async startContainer(id: string): Promise<DockerContainer> {
1417
const container = docker.getContainer(id);
1518
await container.start();
16-
const containers = await this.getContainers(false);
19+
const containers = await this.getContainers({ useCache: false });
1720
const updatedContainer = containers.find((c) => c.id === id);
1821
if (!updatedContainer) {
1922
throw new Error(`Container ${id} not found after starting`);
@@ -24,7 +27,7 @@ export class DockerService {
2427
public async stopContainer(id: string): Promise<DockerContainer> {
2528
const container = docker.getContainer(id);
2629
await container.stop();
27-
const containers = await this.getContainers(false);
30+
const containers = await this.getContainers({ useCache: false });
2831
const updatedContainer = containers.find((c) => c.id === id);
2932
if (!updatedContainer) {
3033
throw new Error(`Container ${id} not found after stopping`);

0 commit comments

Comments
 (0)