mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2026-03-16 17:54:07 +01:00
Migrate to maintained cron lib and remove seconds (#3785)
Co-authored-by: Patrick Schratz <patrick.schratz@gmail.com>
This commit is contained in:
@@ -19,7 +19,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/robfig/cron"
|
||||
"github.com/gdgvda/cron"
|
||||
"github.com/rs/zerolog/log"
|
||||
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server"
|
||||
@@ -31,7 +31,7 @@ import (
|
||||
|
||||
const (
|
||||
// Specifies the interval woodpecker checks for new crons to exec.
|
||||
checkTime = 10 * time.Second
|
||||
checkTime = time.Minute
|
||||
|
||||
// Specifies the batch size of crons to retrieve per check from database.
|
||||
checkItems = 10
|
||||
@@ -71,7 +71,7 @@ func CalcNewNext(schedule string, now time.Time) (time.Time, error) {
|
||||
|
||||
// TODO: allow the users / the admin to set a specific timezone
|
||||
|
||||
c, err := cron.Parse(schedule)
|
||||
c, err := cron.ParseStandard(schedule)
|
||||
if err != nil {
|
||||
return time.Time{}, fmt.Errorf("cron parse schedule: %w", err)
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ package model
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/robfig/cron"
|
||||
"github.com/gdgvda/cron"
|
||||
)
|
||||
|
||||
type Cron struct {
|
||||
@@ -46,7 +46,7 @@ func (c *Cron) Validate() error {
|
||||
return fmt.Errorf("schedule is required")
|
||||
}
|
||||
|
||||
_, err := cron.Parse(c.Schedule)
|
||||
_, err := cron.ParseStandard(c.Schedule)
|
||||
if err != nil {
|
||||
return fmt.Errorf("can't parse schedule: %w", err)
|
||||
}
|
||||
|
||||
53
server/store/datastore/migration/033_cron_without_sec.go
Normal file
53
server/store/datastore/migration/033_cron_without_sec.go
Normal file
@@ -0,0 +1,53 @@
|
||||
// Copyright 2024 Woodpecker Authors
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package migration
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"src.techknowlogick.com/xormigrate"
|
||||
"xorm.io/xorm"
|
||||
|
||||
"go.woodpecker-ci.org/woodpecker/v2/server/model"
|
||||
)
|
||||
|
||||
var cronWithoutSec = xormigrate.Migration{
|
||||
ID: "cron-without-sec",
|
||||
MigrateSession: func(sess *xorm.Session) error {
|
||||
if err := sess.Sync(new(model.Cron)); err != nil {
|
||||
return fmt.Errorf("sync new models failed: %w", err)
|
||||
}
|
||||
|
||||
var crons []*model.Cron
|
||||
if err := sess.Find(&crons); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for _, c := range crons {
|
||||
if strings.HasPrefix(strings.TrimSpace(c.Schedule), "@") {
|
||||
// something like "@daily"
|
||||
continue
|
||||
}
|
||||
|
||||
c.Schedule = strings.SplitN(strings.TrimSpace(c.Schedule), " ", 2)[1]
|
||||
if _, err := sess.Update(c); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
},
|
||||
}
|
||||
@@ -63,6 +63,7 @@ var migrationTasks = []*xormigrate.Migration{
|
||||
&setForgeID,
|
||||
&unifyColumnsTables,
|
||||
&alterTableRegistriesFixRequiredFields,
|
||||
&cronWithoutSec,
|
||||
}
|
||||
|
||||
var allBeans = []any{
|
||||
|
||||
Reference in New Issue
Block a user