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

Migrate to maintained cron lib and remove seconds #3785

Merged
merged 10 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 2 additions & 8 deletions docs/docs/20-usage/45-cron.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,6 @@ To configure cron jobs you need at least push access to the repository.

![cron settings](./cron-settings.png)

The supported schedule syntax can be found at <https://pkg.go.dev/github.com/robfig/cron?utm_source=godoc#hdr-CRON_Expression_Format>. If you need general understanding of the cron syntax <https://crontab.guru/> is a good place to start and experiment.
The supported schedule syntax can be found at <https://pkg.go.dev/github.com/gdgvda/cron#hdr-CRON_Expression_Format>. If you need general understanding of the cron syntax <https://crontab.guru/> is a good place to start and experiment.

Examples: `@every 5m`, `@daily`, `0 30 * * * *` ...

:::info
Woodpeckers cron syntax starts with seconds instead of minutes as used by most linux cron schedulers.

Example: "At minute 30 every hour" would be `0 30 * * * *` instead of `30 * * * *`
:::
Examples: `@every 5m`, `@daily`, `30 * * * *` ...
1 change: 1 addition & 0 deletions docs/docs/91-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Some versions need some changes to the server configuration or the pipeline conf
## 3.0.0

- Update all webhooks by pressing the "Repair all" button in the admin settings as the webhook token claims have changed
- Crons now use standard Linux syntax without seconds

-->

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ require (
github.com/expr-lang/expr v1.16.7
github.com/franela/goblin v0.0.0-20211003143422-0a4f594942bf
github.com/fsnotify/fsnotify v1.7.0
github.com/gdgvda/cron v0.2.0
github.com/gin-gonic/gin v1.10.0
github.com/go-ap/httpsig v0.0.0-20221203064646-3647b4d88fdf
github.com/go-sql-driver/mysql v1.8.1
Expand All @@ -48,7 +49,6 @@ require (
github.com/oklog/ulid/v2 v2.1.0
github.com/pkg/errors v0.9.1
github.com/prometheus/client_golang v1.19.1
github.com/robfig/cron v1.2.0
github.com/rs/zerolog v1.33.0
github.com/stretchr/testify v1.9.0
github.com/swaggo/files v1.0.1
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,8 @@ github.com/fsnotify/fsnotify v1.7.0 h1:8JEhPFa5W2WU7YfeZzPNqzMP6Lwt7L2715Ggo0nos
github.com/fsnotify/fsnotify v1.7.0/go.mod h1:40Bi/Hjc2AVfZrqy+aj+yEI+/bRxZnMJyTJwOpGvigM=
github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0=
github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk=
github.com/gdgvda/cron v0.2.0 h1:oX8qdLZq4tC5StnCsZsTNs2BIzaRjcjmPZ4o+BArKX4=
github.com/gdgvda/cron v0.2.0/go.mod h1:VEwidZXB255kESB5DcUGRWTYZS8KkOBYD1YBn8Wiyx8=
github.com/gin-contrib/gzip v0.0.6 h1:NjcunTcGAj5CO1gn4N8jHOSIeRFHIbn51z6K+xaN4d4=
github.com/gin-contrib/gzip v0.0.6/go.mod h1:QOJlmV2xmayAjkNS2Y8NQsMneuRShOU/kjovCXNuzzk=
github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE=
Expand Down Expand Up @@ -407,8 +409,6 @@ github.com/rivo/uniseg v0.1.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJ
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.6 h1:Sovz9sDSwbOz9tgUy8JpT+KgCkPYJEN/oYzlJiYTNLg=
github.com/rivo/uniseg v0.4.6/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/robfig/cron v1.2.0 h1:ZjScXvvxeQ63Dbyxy76Fj3AT3Ut0aKsyd2/tl3DTMuQ=
github.com/robfig/cron v1.2.0/go.mod h1:JGuDeoQd7Z6yL4zQhZ3OPEVHB7fL6Ka6skscFHfmt2k=
github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
Expand Down
6 changes: 3 additions & 3 deletions server/cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions server/model/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import (
"fmt"

"github.com/robfig/cron"
"github.com/gdgvda/cron"
)

type Cron struct {
Expand Down Expand Up @@ -46,7 +46,7 @@
return fmt.Errorf("schedule is required")
}

_, err := cron.Parse(c.Schedule)
_, err := cron.ParseStandard(c.Schedule)

Check warning on line 49 in server/model/cron.go

View check run for this annotation

Codecov / codecov/patch

server/model/cron.go#L49

Added line #L49 was not covered by tests
if err != nil {
return fmt.Errorf("can't parse schedule: %w", err)
}
Expand Down
48 changes: 48 additions & 0 deletions server/store/datastore/migration/031_cron_without_sec.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// 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)
}

Check warning on line 32 in server/store/datastore/migration/031_cron_without_sec.go

View check run for this annotation

Codecov / codecov/patch

server/store/datastore/migration/031_cron_without_sec.go#L31-L32

Added lines #L31 - L32 were not covered by tests

var crons []*model.Cron
if err := sess.Find(&crons); err != nil {
return err
}

Check warning on line 37 in server/store/datastore/migration/031_cron_without_sec.go

View check run for this annotation

Codecov / codecov/patch

server/store/datastore/migration/031_cron_without_sec.go#L36-L37

Added lines #L36 - L37 were not covered by tests

for _, c := range crons {
c.Schedule = strings.SplitN(c.Schedule, " ", 2)[1]
qwerty287 marked this conversation as resolved.
Show resolved Hide resolved
if _, err := sess.Update(c); err != nil {
return err
}

Check warning on line 43 in server/store/datastore/migration/031_cron_without_sec.go

View check run for this annotation

Codecov / codecov/patch

server/store/datastore/migration/031_cron_without_sec.go#L40-L43

Added lines #L40 - L43 were not covered by tests
}

return nil
},
}
1 change: 1 addition & 0 deletions server/store/datastore/migration/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ var migrationTasks = []*xormigrate.Migration{
&renameLinkToURL,
&cleanRegistryPipeline,
&setForgeID,
&cronWithoutSec,
}

var allBeans = []any{
Expand Down
2 changes: 1 addition & 1 deletion web/src/components/repo/settings/CronTab.vue
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
<InputField
v-slot="{ id }"
:label="$t('repo.settings.crons.schedule.title')"
docs-url="https://pkg.go.dev/github.com/robfig/cron?utm_source=godoc#hdr-CRON_Expression_Format"
docs-url="https://pkg.go.dev/github.com/gdgvda/cron#hdr-CRON_Expression_Format"
>
<TextField
:id="id"
Expand Down