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

break change: upgrade version to v0.6.0, move driver to single repo. #109

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 3 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
branches: [ "master", "develop" ]
pull_request:
branches: [ "master", "develop" ]
# manually start testing.
workflow_dispatch:

jobs:

Expand All @@ -28,7 +30,7 @@ jobs:
go-version: ${{ matrix.go_version }}

- name: Test
run: go test -v -timeout 30m -coverprofile=coverage.txt -covermode=atomic ./...
run: bash scripts/run_all_tests.sh

- name: Upload coverage reports to Codecov
uses: codecov/codecov-action@v4
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.idea/*
bin/
coverage.txt
coverage.html
coverage.html
cov/
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ If use distributed-lock to implement it. I will depends on the system-time of ea
redisCli := redis.NewClient(&redis.Options{
Addr: DefaultRedisAddr,
})
drv := driver.NewRedisDriver(redisCli)
drv := redisdriver.NewDriver(redisCli)
dcron := NewDcron("server1", drv)
```
2. Use cron-language to add task, you should set the `TaskName`, the `TaskName` is the primary-key of each task.
Expand All @@ -55,6 +55,10 @@ dcron.Start()
// blocking start.
dcron.Run()
```
### Drivers

After v0.6.0, We split out Dcron's drivers like etcddriver and redisdriver from main repo, and maintain them in independent repos. For details, please refer to [dcron-contrib](https://github.com/dcron-contrib).


### Example
- [examples](examples/)
Expand Down
5 changes: 4 additions & 1 deletion README_CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ a lightweight distributed job scheduler library based on redis or etcd
redisCli := redis.NewClient(&redis.Options{
Addr: DefaultRedisAddr,
})
drv := driver.NewRedisDriver(redisCli)
drv := redisdriver.NewDriver(redisCli)
dcron := NewDcron("server1", drv)
```
当然,如果你可以自己实现一个自定义的Driver也是可以的,只需要实现[DriverV2](driver/driver.go)接口即可。
Expand All @@ -55,6 +55,9 @@ dcron.Start()
// 使用当前协程同步启动任务,会阻塞当前协程后续逻辑执行
dcron.Run()
```
### Drivers

在v0.6.0版本之后,Dcron将所有的driver从主仓库拆分,并放置在独立仓库进行维护, 详见 [dcron-contrib](https://github.com/dcron-contrib)

### 使用案例
- [examples](examples/)
Expand Down
2 changes: 1 addition & 1 deletion cron/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"sync"
"time"

"github.com/libi/dcron/dlog"
"github.com/dcron-contrib/commons/dlog"
)

// JobWrapper decorates the given Job with some behavior.
Expand Down
2 changes: 1 addition & 1 deletion cron/chain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"testing"
"time"

"github.com/libi/dcron/dlog"
"github.com/dcron-contrib/commons/dlog"
)

func appendingJob(slice *[]int, value int) Job {
Expand Down
2 changes: 1 addition & 1 deletion cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"sync"
"time"

"github.com/libi/dcron/dlog"
"github.com/dcron-contrib/commons/dlog"
)

// Cron keeps track of any number of entries, invoking the associated func as
Expand Down
2 changes: 1 addition & 1 deletion cron/cron_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"testing"
"time"

"github.com/libi/dcron/dlog"
"github.com/dcron-contrib/commons/dlog"
)

// Many tests schedule a job for every second, and then wait at most a second
Expand Down
2 changes: 1 addition & 1 deletion cron/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"os"

"github.com/libi/dcron/dlog"
"github.com/dcron-contrib/commons/dlog"
)

// DefaultLogger is used by Cron if none is specified.
Expand Down
2 changes: 1 addition & 1 deletion cron/option.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package cron
import (
"time"

"github.com/libi/dcron/dlog"
"github.com/dcron-contrib/commons/dlog"
)

// Option represents a modification to the default behavior of a Cron.
Expand Down
19 changes: 11 additions & 8 deletions dcron.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"sync/atomic"
"time"

"github.com/dcron-contrib/commons"
"github.com/dcron-contrib/commons/dlog"
"github.com/libi/dcron/cron"
"github.com/libi/dcron/dlog"
"github.com/libi/dcron/driver"
)

const (
Expand Down Expand Up @@ -59,7 +59,7 @@ type Dcron struct {
}

// NewDcron create a Dcron
func NewDcron(serverName string, driver driver.DriverV2, cronOpts ...cron.Option) *Dcron {
func NewDcron(serverName string, driver commons.DriverV2, cronOpts ...cron.Option) *Dcron {
dcron := newDcron(serverName)
dcron.crOptions = cronOpts
dcron.cr = cron.New(cronOpts...)
Expand All @@ -69,7 +69,7 @@ func NewDcron(serverName string, driver driver.DriverV2, cronOpts ...cron.Option
}

// NewDcronWithOption create a Dcron with Dcron Option
func NewDcronWithOption(serverName string, driver driver.DriverV2, dcronOpts ...Option) *Dcron {
func NewDcronWithOption(serverName string, driver commons.DriverV2, dcronOpts ...Option) *Dcron {
dcron := newDcron(serverName)
for _, opt := range dcronOpts {
opt(dcron)
Expand Down Expand Up @@ -280,19 +280,22 @@ func (d *Dcron) startNodePool() error {
return nil
}

// Stop job
func (d *Dcron) Stop() {
// This function is to Stop the dcron.
// Stop stops the cron scheduler if it is running; otherwise it does nothing.
// A context is returned so the caller can wait for running jobs to complete.
func (d *Dcron) Stop() context.Context {
tick := time.NewTicker(time.Millisecond)
if !d.runningLocally {
d.nodePool.Stop(context.Background())
}
for range tick.C {
if atomic.CompareAndSwapInt32(&d.running, dcronRunning, dcronStopped) {
d.cr.Stop()
d.logger.Infof("dcron stopped")
return
return d.cr.Stop()
}
}
// We ensure this function won't return nil.
return nil
}

func (d *Dcron) reRunRecentJobs(jobNames []string) {
Expand Down
78 changes: 0 additions & 78 deletions dlog/logger.go

This file was deleted.

43 changes: 0 additions & 43 deletions driver/driver.go

This file was deleted.

Loading