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

actions task displays an incorrect time #28323

Closed
ExplodingDragon opened this issue Dec 2, 2023 · 5 comments · Fixed by #28364
Closed

actions task displays an incorrect time #28323

ExplodingDragon opened this issue Dec 2, 2023 · 5 comments · Fixed by #28364
Labels

Comments

@ExplodingDragon
Copy link
Contributor

Description

I'm using sqlite and found this bug during a routine weekly check, not sure how to reproduce it for now.

图片
图片
图片

Gitea Version

main

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

No response

How are you running Gitea?

systemd

Database

SQLite

@yp05327
Copy link
Contributor

yp05327 commented Dec 5, 2023

The duration in the first pic is calculated by the records in action_run table,
and in the second pic, it is calculated by the records in action_task_step table.
So it seems that the data in action_task_step table is correct but the data in action_run table is incorrect.

@yp05327
Copy link
Contributor

yp05327 commented Dec 5, 2023

It seems that this run was scheduled twice.

yesterday (above the wrong duration) is Updated time. Not the Started time and Stopped time.
And the schedule is weekly, and the run before this run is 2 weeks ago, so the last updated time of this run should be 1 weeks ago? But it is yesterday here.

So I guess: yesterday it was scheduled again (or maybe other operations?) , and the Started time was updated.
But this run is already been done, so the status should be done and it would not run again.
So the Stopped time should be the last stopped time which won't be updated for ever, so the duration becomes minus number here.
So if my guess is correct, the date of yesterday would be about 105h37m21s after the real Stopped time.

@yp05327
Copy link
Contributor

yp05327 commented Dec 6, 2023

Ok, I got it. But don't know why. 🤔
image

@yp05327
Copy link
Contributor

yp05327 commented Dec 6, 2023

This issue is not related to cron job.
And there's a easy way to reproduce:

  • stop all your runners which can pick up the workflow.
  • trigger the workflow, and the status will be waiting as there's no runners to run it.
  • cancel it, the status will become failure.
  • start your runner, rerun it
  • after it finished, you will get a minus duration time.

I will try to fix it. This issue is caused by the codes here:

run.Status = aggregateJobStatus(jobs)
if run.Started.IsZero() && run.Status.IsRunning() {
run.Started = timeutil.TimeStampNow()
}
if run.Stopped.IsZero() && run.Status.IsDone() {
run.Stopped = timeutil.TimeStampNow()
}

When a job finished before executed once, e.g. no target runner and canceled manually, the Stopped time is not 0 but the Started time is 0.
So if you rerun it, only Started time will be updated, but the Stopped time won't. Then you will get a minus duration time, as it is calculated by Stopped - Started.

lunny pushed a commit that referenced this issue Jan 19, 2024
… once (#28364)

Fix #28323
Reason was mentioned here:
#28323 (comment)

### Changes: (maybe breaking)
We can rerun jobs in Gitea, so there will be some problems in
calculating duration time.
In this PR, I use the exist `Started` and `Stopped` column to record the
last run time instead of the total time,
and add a new `PreviousDuration` column to record the previous duration
time.
You can also check the cost time of last run:

![image](https://github.com/go-gitea/gitea/assets/18380374/2ca39145-2c92-401a-b78b-43164f7ae061)
henrygoodman pushed a commit to henrygoodman/gitea that referenced this issue Jan 31, 2024
… once (go-gitea#28364)

Fix go-gitea#28323
Reason was mentioned here:
go-gitea#28323 (comment)

### Changes: (maybe breaking)
We can rerun jobs in Gitea, so there will be some problems in
calculating duration time.
In this PR, I use the exist `Started` and `Stopped` column to record the
last run time instead of the total time,
and add a new `PreviousDuration` column to record the previous duration
time.
You can also check the cost time of last run:

![image](https://github.com/go-gitea/gitea/assets/18380374/2ca39145-2c92-401a-b78b-43164f7ae061)
silverwind pushed a commit to silverwind/gitea that referenced this issue Feb 20, 2024
… once (go-gitea#28364)

Fix go-gitea#28323
Reason was mentioned here:
go-gitea#28323 (comment)

### Changes: (maybe breaking)
We can rerun jobs in Gitea, so there will be some problems in
calculating duration time.
In this PR, I use the exist `Started` and `Stopped` column to record the
last run time instead of the total time,
and add a new `PreviousDuration` column to record the previous duration
time.
You can also check the cost time of last run:

![image](https://github.com/go-gitea/gitea/assets/18380374/2ca39145-2c92-401a-b78b-43164f7ae061)
Copy link

github-actions bot commented Mar 1, 2024

Automatically locked because of our CONTRIBUTING guidelines

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants