Skip to content

Commit

Permalink
fix: add argument type parameter to task (#164)
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 authored May 17, 2023
1 parent ca6c30f commit 64606cd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/features/serverTasks/serverTask.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { NamedResource } from "../../namedResource";
import { TaskState } from "./taskState";

export interface ServerTask extends NamedResource {
export interface ServerTask<TArguments = any> extends NamedResource {
Description: string;
State: TaskState;
Completed?: string;
Expand All @@ -19,4 +19,5 @@ export interface ServerTask extends NamedResource {
HasPendingInterruptions: boolean;
CanRerun?: boolean;
HasWarningsOrErrors: boolean;
Arguments: TArguments;
}
8 changes: 4 additions & 4 deletions src/features/serverTasks/spaceServerTaskRepository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,22 @@ export class SpaceServerTaskRepository {
this.spaceName = spaceName;
}

async getById(serverTaskId: string): Promise<ServerTask> {
async getById<TArgument = void>(serverTaskId: string): Promise<ServerTask> {
if (!serverTaskId) {
throw new Error("Server Task Id was not provided");
}
const response = await this.client.request<ServerTask>(`${this.baseApiPathTemplate}/${serverTaskId}`, { spaceName: this.spaceName });
const response = await this.client.request<ServerTask<TArgument>>(`${this.baseApiPathTemplate}/${serverTaskId}`, { spaceName: this.spaceName });
return response;
}

async getByIds(serverTaskIds: string[]): Promise<ServerTask[]> {
async getByIds<TArguments = void>(serverTaskIds: string[]): Promise<ServerTask[]> {
const batchSize = 300;
const idArrays = chunk(serverTaskIds, batchSize);
const promises: Array<Promise<ResourceCollection<ServerTask>>> = [];

for (const [index, ids] of idArrays.entries()) {
promises.push(
this.client.request<ResourceCollection<ServerTask>>(`${this.baseApiPathTemplate}{?skip,take,ids,partialName}`, {
this.client.request<ResourceCollection<ServerTask<TArguments>>>(`${this.baseApiPathTemplate}{?skip,take,ids,partialName}`, {
spaceName: this.spaceName,
ids: ids,
skip: index * batchSize,
Expand Down

0 comments on commit 64606cd

Please sign in to comment.