forked from libi/dcron
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add cron to dcron and splite e2e test cases from other test cases. (l…
…ibi#81) * Deps: updated github.com/go-redis/redis/v8 to github.com/redis/go-redis/v9 (libi#73) * add robfig/cron to dcron (libi#75) * add NodeID function into dcron * add cron lib * fix warning * logger removal : phares1 * update * update * update * Add comments, add split the E2E test cases and other test cases. (libi#80) * add example app to readme * add NodeID function into dcron * add cron lib * fix warning * logger removal : phares1 * update * update * update * update * update * update * update * update test workflow * revert 1.22 * update etcd driver * update * fix get nodes * update * update for fix TAT * Revert "update etcd driver" This reverts commit a21ebf7. * Revert "deps: updated go-redis to v9 (libi#79)" This reverts commit 0b85b24. * update * update * refact etcd * Revert "refact etcd" This reverts commit 049bed1. * Revert "update" This reverts commit 9c71fd6. * update * refactor etcddriver * fix error * update * Revert "update" This reverts commit 6cfcfe6. * Revert "fix error" This reverts commit 99b2d82. * Revert "refactor etcddriver" This reverts commit a576ac3. * update * update * remove comments, and fix * add comments * merge e2e test and normal test * move e2etest to origin path * add timeout to avoid pipeline timeout --------- Co-authored-by: Ava Ackerman <withrjp@gmail.com> Co-authored-by: libi <7769922+libi@users.noreply.github.com>
- Loading branch information
1 parent
143a944
commit 171374b
Showing
35 changed files
with
3,341 additions
and
166 deletions.
There are no files selected for viewing
This file contains 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 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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
.idea | ||
.idea/* | ||
bin/ | ||
bin/ | ||
coverage.txt | ||
coverage.html |
This file contains 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,21 @@ | ||
Copyright (C) 2012 Rob Figueiredo | ||
All Rights Reserved. | ||
|
||
MIT LICENSE | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains 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,3 @@ | ||
# cron | ||
|
||
fork from [robfig/cron](github.com/robfig/cron) |
This file contains 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,97 @@ | ||
package cron | ||
|
||
import ( | ||
"fmt" | ||
"runtime" | ||
"sync" | ||
"time" | ||
|
||
"github.com/libi/dcron/dlog" | ||
) | ||
|
||
// JobWrapper decorates the given Job with some behavior. | ||
type JobWrapper func(Job) Job | ||
|
||
// Chain is a sequence of JobWrappers that decorates submitted jobs with | ||
// cross-cutting behaviors like logging or synchronization. | ||
type Chain struct { | ||
wrappers []JobWrapper | ||
} | ||
|
||
// NewChain returns a Chain consisting of the given JobWrappers. | ||
func NewChain(c ...JobWrapper) Chain { | ||
return Chain{c} | ||
} | ||
|
||
// Then decorates the given job with all JobWrappers in the chain. | ||
// | ||
// This: | ||
// | ||
// NewChain(m1, m2, m3).Then(job) | ||
// | ||
// is equivalent to: | ||
// | ||
// m1(m2(m3(job))) | ||
func (c Chain) Then(j Job) Job { | ||
for i := range c.wrappers { | ||
j = c.wrappers[len(c.wrappers)-i-1](j) | ||
} | ||
return j | ||
} | ||
|
||
// Recover panics in wrapped jobs and log them with the provided logger. | ||
func Recover(logger dlog.Logger) JobWrapper { | ||
return func(j Job) Job { | ||
return FuncJob(func() { | ||
defer func() { | ||
if r := recover(); r != nil { | ||
const size = 64 << 10 | ||
buf := make([]byte, size) | ||
buf = buf[:runtime.Stack(buf, false)] | ||
err, ok := r.(error) | ||
if !ok { | ||
err = fmt.Errorf("%v", r) | ||
} | ||
logger.Errorf("panic: stack %v\n%v\n", err, string(buf)) | ||
} | ||
}() | ||
j.Run() | ||
}) | ||
} | ||
} | ||
|
||
// DelayIfStillRunning serializes jobs, delaying subsequent runs until the | ||
// previous one is complete. Jobs running after a delay of more than a minute | ||
// have the delay logged at Info. | ||
func DelayIfStillRunning(logger dlog.Logger) JobWrapper { | ||
return func(j Job) Job { | ||
var mu sync.Mutex | ||
return FuncJob(func() { | ||
start := time.Now() | ||
mu.Lock() | ||
defer mu.Unlock() | ||
if dur := time.Since(start); dur > time.Minute { | ||
logger.Infof("delay duration=%v", dur) | ||
} | ||
j.Run() | ||
}) | ||
} | ||
} | ||
|
||
// SkipIfStillRunning skips an invocation of the Job if a previous invocation is | ||
// still running. It logs skips to the given logger at Info level. | ||
func SkipIfStillRunning(logger dlog.Logger) JobWrapper { | ||
return func(j Job) Job { | ||
var ch = make(chan struct{}, 1) | ||
ch <- struct{}{} | ||
return FuncJob(func() { | ||
select { | ||
case v := <-ch: | ||
defer func() { ch <- v }() | ||
j.Run() | ||
default: | ||
logger.Infof("skip") | ||
} | ||
}) | ||
} | ||
} |
Oops, something went wrong.