Skip to content

Commit

Permalink
Changes to work with TaskTypeDictionary.get changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ymao1 committed Aug 3, 2024
1 parent 6718717 commit f180148
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,8 +273,8 @@ export function createWorkloadAggregator({
let totalCost = 0;
const taskTypeSummary = taskTypes.reduce((acc, bucket) => {
const value = bucket as TaskTypeWithStatusBucket;
try {
const taskDef = taskDefinitions.get(value.key as string);
const taskDef = taskDefinitions.get(value.key as string);
if (taskDef) {
const cost = value.doc_count * taskDef?.cost ?? TaskCost.Normal;

totalCost += cost;
Expand All @@ -285,7 +285,7 @@ export function createWorkloadAggregator({
status: mapValues(keyBy(value.status.buckets, 'key'), 'doc_count'),
},
});
} catch (err) {
} else {
// task type is not registered with dictionary, do not add to summary
return acc;
}
Expand Down Expand Up @@ -556,10 +556,10 @@ interface DateRangeBucket {
function getTotalCost(taskTypeBuckets: TaskTypeBucket[], definitions: TaskTypeDictionary): number {
let cost = 0;
for (const bucket of taskTypeBuckets) {
try {
const taskDef = definitions.get(bucket.key as string);
const taskDef = definitions.get(bucket.key as string);
if (taskDef) {
cost += bucket.doc_count * taskDef?.cost ?? TaskCost.Normal;
} catch (err) {
} else {
// task type is not registered with dictionary, do not add to cost
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,11 +284,7 @@ describe('taskTypeDictionary', () => {
expect(logger.error).toHaveBeenCalledWith(
`Could not sanitize task definitions: Invalid cost \"23\". Cost must be one of Tiny => 1,Normal => 2,ExtraLarge => 10`
);
expect(() => {
definitions.get('foo');
}).toThrowErrorMatchingInlineSnapshot(
`"Unsupported task type \\"foo\\". Supported types are "`
);
expect(definitions.get('foo')).toEqual(undefined);
});

it('throws error when registering duplicate task type', () => {
Expand Down

0 comments on commit f180148

Please sign in to comment.