incubator-devlake icon indicating copy to clipboard operation
incubator-devlake copied to clipboard

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

Open sstojak1 opened this issue 1 year ago • 1 comments

Search before asking

  • [X] I had searched in the issues and found no similar issues.

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?

  • [ ] Yes I am willing to submit a PR!

Code of Conduct

sstojak1 avatar Jun 20 '24 08:06 sstojak1

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.

dosubot[bot] avatar Jun 20 '24 08:06 dosubot[bot]

This issue has been automatically marked as stale because it has been inactive for 60 days. It will be closed in next 7 days if no further activity occurs.

github-actions[bot] avatar Aug 20 '24 00:08 github-actions[bot]

This issue has been closed because it has been inactive for a long time. You can reopen it if you encounter the similar problem in the future.

github-actions[bot] avatar Aug 28 '24 00:08 github-actions[bot]