Skip to content

Commit 2250b0f

Browse files
refactor: change processBulkRequest response for consumer convenience
1 parent 4f3cba8 commit 2250b0f

File tree

2 files changed

+19
-13
lines changed

2 files changed

+19
-13
lines changed

packages/sdk/src/lib/dataProtectorCore/processBulkRequest.ts

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -241,32 +241,36 @@ export const processBulkRequest = async ({
241241
{ pageSize: Math.max(volume, 10) } // Fetch all deals (min page size 10)
242242
);
243243

244-
const allDealIds = deals.map((deal) => deal.dealid);
245-
const allTaskIds: string[] = [];
244+
const tasks: Array<{
245+
taskId: string;
246+
dealId: string;
247+
bulkIndex: number;
248+
}> = [];
246249

247250
for (const deal of deals) {
248-
const taskids = await Promise.all(
251+
const dealTasks = await Promise.all(
249252
new Array(deal.botSize)
250253
.fill(deal.botFirst)
251-
.map((botFirst, i) =>
252-
iexec.deal.computeTaskId(deal.dealid, botFirst + i)
253-
)
254+
.map(async (botFirst, i) => ({
255+
taskId: await iexec.deal.computeTaskId(deal.dealid, botFirst + i),
256+
dealId: deal.dealid,
257+
bulkIndex: botFirst + i,
258+
}))
254259
);
255-
allTaskIds.push(...taskids);
260+
tasks.push(...dealTasks);
256261
}
257262

258263
vOnStatusUpdate({
259264
title: 'MATCH_ORDERS_LOOP',
260265
isDone: true,
261266
payload: {
262-
totalMatches: allDealIds.length,
267+
totalMatches: deals.length,
263268
totalVolume: volume,
264269
},
265270
});
266271

267272
return {
268-
dealsIds: allDealIds,
269-
tasksIds: allTaskIds,
273+
tasks: tasks.sort((a, b) => a.bulkIndex - b.bulkIndex),
270274
};
271275
} catch (error) {
272276
console.error('[processBulkRequest] ERROR', error);

packages/sdk/src/lib/types/coreTypes.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -576,7 +576,9 @@ export type ProcessBulkRequestParams = {
576576
};
577577

578578
export type ProcessBulkRequestResponse = {
579-
dealsIds: string[];
580-
tasksIds: string[];
581-
// results: { status: 'success' | 'error'; data: ArrayBuffer }[]; // TODO wait and get tasks results ?
579+
tasks: Array<{
580+
taskId: string;
581+
dealId: string;
582+
bulkIndex: number;
583+
}>;
582584
};

0 commit comments

Comments
 (0)