Skip to content

Commit

Permalink
Fixing types
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Aug 3, 2024
1 parent a81787a commit 8d6ac21
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions x-pack/plugins/task_manager/server/task_pool/cost_capacity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ export class CostCapacity implements ICapacity {
public usedCapacity(tasksInPool: Map<string, TaskRunner>) {
let result = 0;
tasksInPool.forEach((task) => {
result += task.definition.cost;
if (task.definition?.cost) {
result += task.definition.cost;
}
});
return result;
}
Expand All @@ -56,7 +58,7 @@ export class CostCapacity implements ICapacity {
public getUsedCapacityByType(tasksInPool: TaskRunner[], type: string) {
return tasksInPool.reduce(
(count, runningTask) =>
runningTask.definition.type === type ? count + runningTask.definition.cost : count,
runningTask.definition?.type === type ? count + runningTask.definition.cost : count,
0
);
}
Expand Down Expand Up @@ -91,7 +93,7 @@ export class CostCapacity implements ICapacity {

let capacityAccumulator = 0;
for (const task of tasks) {
const taskCost = task.definition.cost;
const taskCost = task.definition?.cost ?? 0;
if (capacityAccumulator + taskCost <= availableCapacity) {
tasksToRun.push(task);
capacityAccumulator += taskCost;
Expand Down

0 comments on commit 8d6ac21

Please sign in to comment.