()
| 623 | }; |
| 624 | |
| 625 | const updateTaskStatus = async () => { |
| 626 | try { |
| 627 | const snapshot = await tasksModel.where("status", "==", "COMPLETED").get(); |
| 628 | const tasksStatusCompleted = []; |
| 629 | let summary = { |
| 630 | totalTasks: snapshot.size, |
| 631 | totalUpdatedStatus: 0, |
| 632 | totalOperationsFailed: 0, |
| 633 | updatedTaskDetails: [], |
| 634 | failedTaskDetails: [], |
| 635 | }; |
| 636 | |
| 637 | if (snapshot.size === 0) { |
| 638 | return summary; |
| 639 | } |
| 640 | |
| 641 | snapshot.forEach((task) => { |
| 642 | const id = task.id; |
| 643 | const taskData = task.data(); |
| 644 | tasksStatusCompleted.push({ ...taskData, id }); |
| 645 | }); |
| 646 | const taskStatusCompletedChunks = chunks(tasksStatusCompleted, DOCUMENT_WRITE_SIZE); |
| 647 | |
| 648 | const updatedTasksPromises = await Promise.all( |
| 649 | taskStatusCompletedChunks.map(async (tasks) => { |
| 650 | const res = await updateTaskStatusToDone(tasks); |
| 651 | return { |
| 652 | totalUpdatedStatus: res.totalUpdatedStatus, |
| 653 | totalOperationsFailed: res.totalOperationsFailed, |
| 654 | updatedTaskDetails: res.updatedTaskDetails, |
| 655 | failedTaskDetails: res.failedTaskDetails, |
| 656 | }; |
| 657 | }) |
| 658 | ); |
| 659 | |
| 660 | updatedTasksPromises.forEach((res) => { |
| 661 | summary = { |
| 662 | ...summary, |
| 663 | totalUpdatedStatus: (summary.totalUpdatedStatus += res.totalUpdatedStatus), |
| 664 | totalOperationsFailed: (summary.totalOperationsFailed += res.totalOperationsFailed), |
| 665 | updatedTaskDetails: [...summary.updatedTaskDetails, ...res.updatedTaskDetails], |
| 666 | failedTaskDetails: [...summary.failedTaskDetails, ...res.failedTaskDetails], |
| 667 | }; |
| 668 | }); |
| 669 | |
| 670 | if (summary.totalOperationsFailed === summary.totalTasks) { |
| 671 | throw Error(INTERNAL_SERVER_ERROR); |
| 672 | } |
| 673 | |
| 674 | return summary; |
| 675 | } catch (error) { |
| 676 | logger.error(`Error in updating task status: ${error}`); |
| 677 | throw error; |
| 678 | } |
| 679 | }; |
| 680 | |
| 681 | const updateOrphanTasksStatus = async () => { |
| 682 | try { |
nothing calls this directly
no test coverage detected