-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Replace gogs/cron with go-co-op/gocron #25977
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
Merged
Merged
Changes from 18 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
5f46407
Replace gogs/cron with go-co-op/gocron
harryzcy aa4f3fc
Run `make tidy`
harryzcy bd4123a
Fix
harryzcy ceb0720
Merge branch 'main' into replace-cron
harryzcy 73d9f4a
Revert "Fix" that wrong file is added
harryzcy 5e1e925
Apply correct fix
harryzcy 7c6208c
Auto detect of cron schedule has seconds
harryzcy a132628
Add some tests
harryzcy 9c15e77
Add copyright
harryzcy cf5d748
Run `make fmt`
harryzcy c1dedd5
Merge branch 'main' into replace-cron
harryzcy 35a8e98
Merge branch 'main' into replace-cron
harryzcy 94b2eae
Merge branch 'main' into replace-cron
harryzcy 7e48fc0
Merge branch 'main' into replace-cron
harryzcy 2056095
Merge branch 'main' into replace-cron
harryzcy 3e37606
Use `scheduler` variable for readability
harryzcy 7abc89a
Merge branch 'main' into replace-cron
harryzcy c7b0ca4
Merge branch 'main' into replace-cron
harryzcy ac90498
Fix variable shadowing issue
harryzcy 3d6366f
Merge branch 'main' into replace-cron
harryzcy b485bf8
Update services/cron/tasks.go
harryzcy 7df958e
Add "strings" import
harryzcy 981cec9
Merge branch 'main' into replace-cron
GiteaBot 2a9c942
Merge branch 'main' into replace-cron
GiteaBot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright 2023 The Gitea Authors. All rights reserved. | ||
// SPDX-License-Identifier: MIT | ||
|
||
package cron | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestAddTaskToScheduler(t *testing.T) { | ||
assert.Len(t, scheduler.Jobs(), 0) | ||
defer scheduler.Clear() | ||
|
||
// no seconds | ||
err := addTaskToScheduler(&Task{ | ||
Name: "task 1", | ||
config: &BaseConfig{ | ||
Schedule: "5 4 * * *", | ||
}, | ||
}) | ||
assert.NoError(t, err) | ||
assert.Len(t, scheduler.Jobs(), 1) | ||
assert.Equal(t, "task 1", scheduler.Jobs()[0].Tags()[0]) | ||
assert.Equal(t, "5 4 * * *", scheduler.Jobs()[0].Tags()[1]) | ||
|
||
// with seconds | ||
err = addTaskToScheduler(&Task{ | ||
Name: "task 2", | ||
config: &BaseConfig{ | ||
Schedule: "30 5 4 * * *", | ||
}, | ||
}) | ||
assert.NoError(t, err) | ||
assert.Len(t, scheduler.Jobs(), 2) | ||
assert.Equal(t, "task 2", scheduler.Jobs()[1].Tags()[0]) | ||
assert.Equal(t, "30 5 4 * * *", scheduler.Jobs()[1].Tags()[1]) | ||
} | ||
|
||
func TestScheduleHasSeconds(t *testing.T) { | ||
tests := []struct { | ||
schedule string | ||
hasSecond bool | ||
}{ | ||
{"* * * * * *", true}, | ||
{"* * * * *", false}, | ||
{"5 4 * * *", false}, | ||
{"5 4 * * *", false}, | ||
{"5,8 4 * * *", false}, | ||
{"* * * * * *", true}, | ||
{"5,8 4 * * *", false}, | ||
} | ||
|
||
for i, test := range tests { | ||
t.Run(strconv.Itoa(i), func(t *testing.T) { | ||
assert.Equal(t, test.hasSecond, scheduleHasSeconds(test.schedule)) | ||
}) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.