[Bug][Framework] Devlake tasks table began_at field not correct
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
- Create a new Devlake project with a few connections.
- Run the project.
- Download the logs through the UI.
- Check the specific task logs for the start time. Note that this start time will differ from the
began_atfield in the_devlake_taskstable.
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
- [X] I agree to follow this project's Code of Conduct
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.
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.
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.