@@ -17,10 +17,8 @@ import (
1717 "forgejo.org/modules/timeutil"
1818 "forgejo.org/modules/util"
1919
20- runnerv1 "code.gitea.io/actions-proto-go/runner/v1"
2120 lru "github.com/hashicorp/golang-lru/v2"
2221 "github.com/nektos/act/pkg/jobparser"
23- "google.golang.org/protobuf/types/known/timestamppb"
2422 "xorm.io/builder"
2523)
2624
@@ -337,89 +335,6 @@ func UpdateTask(ctx context.Context, task *ActionTask, cols ...string) error {
337335 return err
338336}
339337
340- // UpdateTaskByState updates the task by the state.
341- // It will always update the task if the state is not final, even there is no change.
342- // So it will update ActionTask.Updated to avoid the task being judged as a zombie task.
343- func UpdateTaskByState (ctx context.Context , runnerID int64 , state * runnerv1.TaskState ) (* ActionTask , error ) {
344- stepStates := map [int64 ]* runnerv1.StepState {}
345- for _ , v := range state .Steps {
346- stepStates [v .Id ] = v
347- }
348-
349- ctx , commiter , err := db .TxContext (ctx )
350- if err != nil {
351- return nil , err
352- }
353- defer commiter .Close ()
354-
355- e := db .GetEngine (ctx )
356-
357- task := & ActionTask {}
358- if has , err := e .ID (state .Id ).Get (task ); err != nil {
359- return nil , err
360- } else if ! has {
361- return nil , util .ErrNotExist
362- } else if runnerID != task .RunnerID {
363- return nil , fmt .Errorf ("invalid runner for task" )
364- }
365-
366- if task .Status .IsDone () {
367- // the state is final, do nothing
368- return task , nil
369- }
370-
371- // state.Result is not unspecified means the task is finished
372- if state .Result != runnerv1 .Result_RESULT_UNSPECIFIED {
373- task .Status = Status (state .Result )
374- task .Stopped = timeutil .TimeStamp (state .StoppedAt .AsTime ().Unix ())
375- if err := UpdateTask (ctx , task , "status" , "stopped" ); err != nil {
376- return nil , err
377- }
378- if _ , err := UpdateRunJob (ctx , & ActionRunJob {
379- ID : task .JobID ,
380- Status : task .Status ,
381- Stopped : task .Stopped ,
382- }, nil ); err != nil {
383- return nil , err
384- }
385- } else {
386- // Force update ActionTask.Updated to avoid the task being judged as a zombie task
387- task .Updated = timeutil .TimeStampNow ()
388- if err := UpdateTask (ctx , task , "updated" ); err != nil {
389- return nil , err
390- }
391- }
392-
393- if err := task .LoadAttributes (ctx ); err != nil {
394- return nil , err
395- }
396-
397- for _ , step := range task .Steps {
398- var result runnerv1.Result
399- if v , ok := stepStates [step .Index ]; ok {
400- result = v .Result
401- step .LogIndex = v .LogIndex
402- step .LogLength = v .LogLength
403- step .Started = convertTimestamp (v .StartedAt )
404- step .Stopped = convertTimestamp (v .StoppedAt )
405- }
406- if result != runnerv1 .Result_RESULT_UNSPECIFIED {
407- step .Status = Status (result )
408- } else if step .Started != 0 {
409- step .Status = StatusRunning
410- }
411- if _ , err := e .ID (step .ID ).Update (step ); err != nil {
412- return nil , err
413- }
414- }
415-
416- if err := commiter .Commit (); err != nil {
417- return nil , err
418- }
419-
420- return task , nil
421- }
422-
423338func FindOldTasksToExpire (ctx context.Context , olderThan timeutil.TimeStamp , limit int ) ([]* ActionTask , error ) {
424339 e := db .GetEngine (ctx )
425340
@@ -430,13 +345,6 @@ func FindOldTasksToExpire(ctx context.Context, olderThan timeutil.TimeStamp, lim
430345 Find (& tasks )
431346}
432347
433- func convertTimestamp (timestamp * timestamppb.Timestamp ) timeutil.TimeStamp {
434- if timestamp .GetSeconds () == 0 && timestamp .GetNanos () == 0 {
435- return timeutil .TimeStamp (0 )
436- }
437- return timeutil .TimeStamp (timestamp .AsTime ().Unix ())
438- }
439-
440348func logFileName (repoFullName string , taskID int64 ) string {
441349 ret := fmt .Sprintf ("%s/%02x/%d.log" , repoFullName , taskID % 256 , taskID )
442350
0 commit comments