Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: not update sub task progress if progress less than 1 pct #8152

Merged
merged 1 commit into from
Oct 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading