1
0
Fork 0
mirror of https://code.forgejo.org/forgejo/runner.git synced 2025-09-15 18:57:01 +00:00

feat: log a descriptive message when a job exceeds the config timeout

- change the argument from string to error to differentiate
  a timeout error
- when there is a timeout, display a message more descriptive than
  "context deadline"
- always set the StoppedAt state value instead of only if the
  result was unspecified: it is the last state update.
This commit is contained in:
Earl Warren 2025-08-16 19:27:17 +02:00
parent bd2b7d2b32
commit 25879b92f4
No known key found for this signature in database
GPG key ID: 0579CB2928A78A00
3 changed files with 115 additions and 17 deletions

View file

@ -236,13 +236,24 @@ func (r *Reporter) SetOutputs(outputs map[string]string) error {
return errors.Join(errs...)
}
func (r *Reporter) Close(lastWords string) error {
const (
closeTimeoutMessage = "The runner cancelled the job because it exceeds the maximum run time"
closeCancelledMessage = "Cancelled"
)
func (r *Reporter) Close(runErr error) error {
r.closed = true
r.stateMu.Lock()
if r.state.Result == runnerv1.Result_RESULT_UNSPECIFIED {
if lastWords == "" {
lastWords = "Early termination"
var lastWords string
if errors.Is(runErr, context.DeadlineExceeded) {
lastWords = closeTimeoutMessage
r.state.Result = runnerv1.Result_RESULT_CANCELLED
} else if r.state.Result == runnerv1.Result_RESULT_UNSPECIFIED {
if runErr == nil {
lastWords = closeCancelledMessage
} else {
lastWords = runErr.Error()
}
for _, v := range r.state.Steps {
if v.Result == runnerv1.Result_RESULT_UNSPECIFIED {
@ -250,17 +261,18 @@ func (r *Reporter) Close(lastWords string) error {
}
}
r.state.Result = runnerv1.Result_RESULT_FAILURE
r.logRows = append(r.logRows, &runnerv1.LogRow{
Time: timestamppb.Now(),
Content: lastWords,
})
r.state.StoppedAt = timestamppb.Now()
} else if lastWords != "" {
} else if runErr != nil {
lastWords = runErr.Error()
r.state.Result = runnerv1.Result_RESULT_FAILURE
}
if lastWords != "" {
r.logRows = append(r.logRows, &runnerv1.LogRow{
Time: timestamppb.Now(),
Content: lastWords,
})
}
r.state.StoppedAt = timestamppb.Now()
r.stateMu.Unlock()
return retry.Do(func() error {