Skip to content

Commit

Permalink
break change: upgrade version to v0.6.0, move driver to single repo. (#…
Browse files Browse the repository at this point in the history
…109)

* add a context return value from Stop function like cron. (#100)

add a context return value from Stop function like cron

* move driver/integrationtest to inner mod (#103)

* update common package

* update

* update

* set go as 1.19

* add integration test

* let integrationtest cover dcron

* update test script

* update

* update fix

* update gocovmerge to v1.0.4

* update gomod

* update to new develop version (#104)

* fix go mod error, split commons out. (#105)

* update

* update

* move commons to dcron-contrib

* fix pipeline

* 拆分所有的drivers (#107)

* move etcd / redis driver out to dcron-contrib

* update run tests script

* update readme (#108)
  • Loading branch information
dxyinme authored Oct 8, 2024
1 parent b0e3dac commit fa69d63
Show file tree
Hide file tree
Showing 38 changed files with 804 additions and 1,551 deletions.
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

0 comments on commit fa69d63

Please sign in to comment.