Skip to content

Commit

Permalink
feat: not update sub task progress if progress less than 1 pct (#8152)
Browse files Browse the repository at this point in the history
[Refactor][core]Data inflation when using postgres #8142
  • Loading branch information
narrowizard authored Oct 23, 2024
1 parent edd7dc0 commit f0bb123
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions backend/core/runner/run_task.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ package runner
import (
gocontext "context"
"fmt"
"github.com/apache/incubator-devlake/core/models/common"
"strings"
"time"

"github.com/apache/incubator-devlake/core/models/common"

"github.com/apache/incubator-devlake/core/context"
"github.com/apache/incubator-devlake/core/dal"
"github.com/apache/incubator-devlake/core/errors"
Expand Down Expand Up @@ -354,6 +355,7 @@ func UpdateProgressDetail(basicRes context.BasicRes, taskId uint64, progressDeta
Model: common.Model{ID: taskId},
}
subtask := &models.Subtask{}
originalFinishedRecords := progressDetail.FinishedRecords
switch p.Type {
case plugin.TaskSetProgress:
progressDetail.TotalSubTasks = p.Total
Expand All @@ -373,14 +375,22 @@ func UpdateProgressDetail(basicRes context.BasicRes, taskId uint64, progressDeta
case plugin.SetCurrentSubTask:
progressDetail.SubTaskName = p.SubTaskName
progressDetail.SubTaskNumber = p.SubTaskNumber
// reset finished records
progressDetail.FinishedRecords = 0
}
// update subtask progress
where := dal.Where("task_id = ? and name = ?", taskId, progressDetail.SubTaskName)
err := basicRes.GetDal().UpdateColumns(subtask, []dal.DalSet{
{ColumnName: "finished_records", Value: progressDetail.FinishedRecords},
}, where)
if err != nil {
basicRes.GetLogger().Error(err, "failed to update _devlake_subtasks progress")
currentFinishedRecords := progressDetail.FinishedRecords
currentTotalRecords := progressDetail.TotalRecords
// update progress if progress is more than 1%
// or there is progress if no total record provided
if (currentTotalRecords > 0 && float64(currentFinishedRecords-originalFinishedRecords)/float64(currentTotalRecords) > 0.01) || (currentTotalRecords <= 0 && currentFinishedRecords > originalFinishedRecords) {
// update subtask progress
where := dal.Where("task_id = ? and name = ?", taskId, progressDetail.SubTaskName)
err := basicRes.GetDal().UpdateColumns(subtask, []dal.DalSet{
{ColumnName: "finished_records", Value: progressDetail.FinishedRecords},
}, where)
if err != nil {
basicRes.GetLogger().Error(err, "failed to update _devlake_subtasks progress")
}
}
}

Expand Down

0 comments on commit f0bb123

Please sign in to comment.