|
@@ -145,29 +145,39 @@ export async function getUnfinishTrackTaskDetails(
|
|
|
trackTaskId: number,
|
|
|
count = 10
|
|
|
) {
|
|
|
- const limitCount = Math.max(10, Math.min(100, count));
|
|
|
- const rows = await TrackTaskDetail.findAll({
|
|
|
- where: { status: TRACK_TASK_DETAIL_STATUS.INIT, trackTaskId },
|
|
|
- limit: limitCount,
|
|
|
- }).catch((err) => {
|
|
|
- console.dir(err);
|
|
|
- });
|
|
|
- if (!rows || !rows.length) return null;
|
|
|
+ const t = await sequelize.transaction();
|
|
|
|
|
|
- await TrackTaskDetail.update(
|
|
|
- {
|
|
|
- status: TRACK_TASK_DETAIL_STATUS.RUNNING,
|
|
|
- },
|
|
|
- {
|
|
|
- where: {
|
|
|
- id: {
|
|
|
- [Op.in]: rows.map((row) => row.dataValues.id),
|
|
|
+ try {
|
|
|
+ const limitCount = Math.max(10, Math.min(100, count));
|
|
|
+ const rows = await TrackTaskDetail.findAll({
|
|
|
+ where: { status: TRACK_TASK_DETAIL_STATUS.INIT, trackTaskId },
|
|
|
+ limit: limitCount,
|
|
|
+ transaction: t,
|
|
|
+ });
|
|
|
+
|
|
|
+ if (rows.length) {
|
|
|
+ await TrackTaskDetail.update(
|
|
|
+ {
|
|
|
+ status: TRACK_TASK_DETAIL_STATUS.RUNNING,
|
|
|
},
|
|
|
- },
|
|
|
+ {
|
|
|
+ where: {
|
|
|
+ id: {
|
|
|
+ [Op.in]: rows.map((row) => row.dataValues.id),
|
|
|
+ },
|
|
|
+ },
|
|
|
+ transaction: t,
|
|
|
+ }
|
|
|
+ );
|
|
|
}
|
|
|
- );
|
|
|
|
|
|
- return rows.map((row) => row.dataValues);
|
|
|
+ await t.commit();
|
|
|
+
|
|
|
+ return rows.map((row) => row.dataValues);
|
|
|
+ } catch (error) {
|
|
|
+ await t.rollback();
|
|
|
+ return Promise.reject(error);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
export async function updateTrackTaskDetailStatus(data: {
|