apache / incubator-devlake

Apache DevLake is an open-source dev data platform to ingest, analyze, and visualize the fragmented data from DevOps tools, extracting insights for engineering excellence, developer experience, and community growth.
https://devlake.apache.org/
Apache License 2.0
2.5k stars 493 forks source link

[Bug][Framework] Devlake tasks table began_at field not correct #7639

Open sstojak1 opened 1 week ago

sstojak1 commented 1 week ago

Search before asking

What happened

The _devlake_tasks table lists the tasks associated with a specific pipeline from the _devlake_pipelines table.

There is an issue with the began_at field in the _devlake_tasks table, as it currently mirrors the value in the _devlake_pipelines table. This causes the spent_seconds field to be inaccurate, making it difficult to calculate the correct duration of a task.

What do you expect to happen

began_at value is correctly populated for _devlake_tasks table.

How to reproduce

  1. Create a new Devlake project with a few connections.
  2. Run the project.
  3. Download the logs through the UI.
  4. Check the specific task logs for the start time. Note that this start time will differ from the began_at field in the _devlake_tasks table.

Anything else

No response

Version

v1.0.0-beta3

Are you willing to submit PR?

Code of Conduct

dosubot[bot] commented 1 week ago

The issue with the began_at field in the _devlake_tasks table mirroring the value from the _devlake_pipelines table is due to the began_at field not being set correctly for individual tasks. To resolve this, ensure that the began_at field for each task is set when the task starts, rather than inheriting the value from the pipeline.

Here's an example of how to set the began_at field correctly:

func StartTask(task *Task) {
    now := time.Now()
    task.BeganAt = &now
    // Save the task to the database
    db.Save(task)
}

This function should be called when the task starts, ensuring that the began_at field is set to the current time. This will help in accurately calculating the spent_seconds field.

Additionally, you can use the logging functionality provided by the getTaskLogger function to trace the exact point at which the began_at field is set. Add logging right before and after setting the began_at field:

logger.Info("Setting began_at for task: %d", task.ID)
beganAt := time.Now()
if task.BeganAt != nil {
    beganAt = *task.BeganAt
}
logger.Info("began_at set to: %v for task: %d", beganAt, task.ID)

This will help you trace and debug the setting of the began_at field for tasks [1][2].

To continue talking to Dosu, mention @dosu.