Skip to content
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
22 changes: 15 additions & 7 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 @@ -353,6 +354,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 @@ -369,6 +371,17 @@ func UpdateProgressDetail(basicRes context.BasicRes, taskId uint64, progressDeta
progressDetail.TotalRecords = p.Total
case plugin.SubTaskIncProgress:
progressDetail.FinishedRecords = p.Current
case plugin.SetCurrentSubTask:
progressDetail.SubTaskName = p.SubTaskName
progressDetail.SubTaskNumber = p.SubTaskNumber
// reset finished records
progressDetail.FinishedRecords = 0
}
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{
Expand All @@ -377,11 +390,6 @@ func UpdateProgressDetail(basicRes context.BasicRes, taskId uint64, progressDeta
if err != nil {
basicRes.GetLogger().Error(err, "failed to update _devlake_subtasks progress")
}
case plugin.SetCurrentSubTask:
progressDetail.SubTaskName = p.SubTaskName
progressDetail.SubTaskNumber = p.SubTaskNumber
default:
return
}
}

Expand Down Expand Up @@ -417,7 +425,7 @@ func recordSubtask(basicRes context.BasicRes, subtask *models.Subtask) {
{ColumnName: "began_at", Value: subtask.BeganAt},
{ColumnName: "finished_at", Value: subtask.FinishedAt},
{ColumnName: "spent_seconds", Value: subtask.SpentSeconds},
{ColumnName: "finished_records", Value: subtask.FinishedRecords},
//{ColumnName: "finished_records", Value: subtask.FinishedRecords}, // FinishedRecords is zero always.
{ColumnName: "number", Value: subtask.Number},
}, where); err != nil {
basicRes.GetLogger().Error(err, "error writing subtask %d status to DB: %v", subtask.ID)
Expand Down