code.gitea.io/gitea@v1.21.7/models/actions/schedule_spec.go (about)

     1  // Copyright 2023 The Gitea Authors. All rights reserved.
     2  // SPDX-License-Identifier: MIT
     3  
     4  package actions
     5  
     6  import (
     7  	"context"
     8  
     9  	"code.gitea.io/gitea/models/db"
    10  	repo_model "code.gitea.io/gitea/models/repo"
    11  	"code.gitea.io/gitea/modules/timeutil"
    12  
    13  	"github.com/robfig/cron/v3"
    14  )
    15  
    16  // ActionScheduleSpec represents a schedule spec of a workflow file
    17  type ActionScheduleSpec struct {
    18  	ID         int64
    19  	RepoID     int64                  `xorm:"index"`
    20  	Repo       *repo_model.Repository `xorm:"-"`
    21  	ScheduleID int64                  `xorm:"index"`
    22  	Schedule   *ActionSchedule        `xorm:"-"`
    23  
    24  	// Next time the job will run, or the zero time if Cron has not been
    25  	// started or this entry's schedule is unsatisfiable
    26  	Next timeutil.TimeStamp `xorm:"index"`
    27  	// Prev is the last time this job was run, or the zero time if never.
    28  	Prev timeutil.TimeStamp
    29  	Spec string
    30  
    31  	Created timeutil.TimeStamp `xorm:"created"`
    32  	Updated timeutil.TimeStamp `xorm:"updated"`
    33  }
    34  
    35  func (s *ActionScheduleSpec) Parse() (cron.Schedule, error) {
    36  	return cronParser.Parse(s.Spec)
    37  }
    38  
    39  func init() {
    40  	db.RegisterModel(new(ActionScheduleSpec))
    41  }
    42  
    43  func UpdateScheduleSpec(ctx context.Context, spec *ActionScheduleSpec, cols ...string) error {
    44  	sess := db.GetEngine(ctx).ID(spec.ID)
    45  	if len(cols) > 0 {
    46  		sess.Cols(cols...)
    47  	}
    48  	_, err := sess.Update(spec)
    49  	return err
    50  }