Skip to content

Commit 5363c51

Browse files
committed
修改module name
1 parent 8c47b82 commit 5363c51

File tree

7 files changed

+79
-25
lines changed

7 files changed

+79
-25
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2015 Roy Lee <roylee0704@gmail.com>
3+
Copyright (c) 2023 Roy Lee <roylee0704@gmail.com>, fakeYanss
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy of
66
this software and associated documentation files (the "Software"), to deal in

README.md

Lines changed: 50 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55

66
Gron provides a clear syntax for writing and deploying cron jobs.
77

8+
**This is a fork repo of [github.com/roylee0704/gron](https://github.com/roylee0704/gron).**
9+
10+
Just add feature of canceling job.
11+
812
## Goals
913

1014
- Minimalist APIs for scheduling jobs.
@@ -15,7 +19,8 @@ Gron provides a clear syntax for writing and deploying cron jobs.
1519
## Installation
1620

1721
```sh
18-
$ go get github.com/roylee0704/gron
22+
# $ go get github.com/roylee0704/gron
23+
$ go get github.com/fakeYanss/gron
1924
```
2025

2126
## Usage
@@ -27,7 +32,8 @@ package main
2732
import (
2833
"fmt"
2934
"time"
30-
"github.com/roylee0704/gron"
35+
// "github.com/roylee0704/gron"
36+
"github.com/fakeYanss/gron"
3137
)
3238

3339
func main() {
@@ -53,7 +59,8 @@ gron.Every(1*time.Hour)
5359

5460
Also support `Day`, `Week` by importing `gron/xtime`:
5561
```go
56-
import "github.com/roylee0704/gron/xtime"
62+
// import "github.com/roylee0704/gron/xtime"
63+
import "github.com/fakeYanss/gron/xtime"
5764

5865
gron.Every(1 * xtime.Day)
5966
gron.Every(1 * xtime.Week)
@@ -117,7 +124,7 @@ type canceledJob struct { // implements of JobWithCancel interface
117124
id string
118125
}
119126

120-
func (j *canceledJob) JobID() {
127+
func (j *canceledJob) JobID() string {
121128
return id
122129
}
123130

@@ -145,42 +152,68 @@ package main
145152

146153
import (
147154
"fmt"
148-
"github.com/roylee0704/gron"
149-
"github.com/roylee0704/gron/xtime"
155+
"time"
156+
157+
"github.com/fakeYanss/gron"
158+
"github.com/fakeYanss/gron/xtime"
150159
)
151160

152-
type PrintJob struct{ Msg string }
161+
type printJob struct{ Msg string }
153162

154-
func (p PrintJob) Run() {
163+
func (p printJob) Run() {
155164
fmt.Println(p.Msg)
156165
}
157166

158-
func main() {
167+
type canceledJob struct { // implements of JobWithCancel interface
168+
id string
169+
}
170+
171+
func (j *canceledJob) JobID() string {
172+
return j.id
173+
}
174+
175+
func (j *canceledJob) Run() {
176+
fmt.Printf("job %s run\n", j.id)
177+
}
159178

179+
func main() {
160180
var (
161-
// schedules
162181
daily = gron.Every(1 * xtime.Day)
163182
weekly = gron.Every(1 * xtime.Week)
164183
monthly = gron.Every(30 * xtime.Day)
165184
yearly = gron.Every(365 * xtime.Day)
166-
167-
// contrived jobs
168-
purgeTask = func() { fmt.Println("purge aged records") }
185+
purgeTask = func() { fmt.Println("purge unwanted records") }
169186
printFoo = printJob{"Foo"}
170187
printBar = printJob{"Bar"}
171188
)
172189

173190
c := gron.New()
174191

175-
c.Add(daily.At("12:30"), printFoo)
192+
c.AddFunc(gron.Every(1*time.Hour), func() {
193+
fmt.Println("Every 1 hour")
194+
})
195+
c.Start()
196+
176197
c.AddFunc(weekly, func() { fmt.Println("Every week") })
198+
c.Add(daily.At("12:30"), printFoo)
177199
c.Start()
178200

179-
// Jobs may also be added to a running Gron
201+
// Jobs may also be added to a running Cron
180202
c.Add(monthly, printBar)
181203
c.AddFunc(yearly, purgeTask)
182204

183-
// Stop Gron (running jobs are not halted).
184-
c.Stop()
205+
c.AddFuncWithJobID(gron.Every(1*time.Second), "job-id-1", func() {
206+
fmt.Println("job-id-1 runs every second")
207+
})
208+
c.AddCancelingJob(gron.Every(1*time.Second), &canceledJob{id: "job-id-2"})
209+
c.Start()
210+
211+
time.Sleep(5 * time.Second)
212+
c.Cancel("job-id-1")
213+
time.Sleep(5 * time.Second)
214+
215+
// Stop the scheduler (does not stop any jobs already running).
216+
defer c.Stop()
185217
}
218+
186219
```

cron_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
"testing"
1010
"time"
1111

12-
"github.com/roylee0704/gron/xtime"
12+
"github.com/fakeYanss/gron/xtime"
1313
)
1414

1515
// Most test jobs scheduled to run at 1 second mark.

example/main.go

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"fmt"
55
"time"
66

7-
"github.com/roylee0704/gron"
8-
"github.com/roylee0704/gron/xtime"
7+
"github.com/fakeYanss/gron"
8+
"github.com/fakeYanss/gron/xtime"
99
)
1010

1111
type printJob struct{ Msg string }
@@ -14,8 +14,19 @@ func (p printJob) Run() {
1414
fmt.Println(p.Msg)
1515
}
1616

17-
func main() {
17+
type canceledJob struct { // implements of JobWithCancel interface
18+
id string
19+
}
20+
21+
func (j *canceledJob) JobID() string {
22+
return j.id
23+
}
24+
25+
func (j *canceledJob) Run() {
26+
fmt.Printf("job %s run\n", j.id)
27+
}
1828

29+
func main() {
1930
var (
2031
daily = gron.Every(1 * xtime.Day)
2132
weekly = gron.Every(1 * xtime.Week)
@@ -41,6 +52,16 @@ func main() {
4152
c.Add(monthly, printBar)
4253
c.AddFunc(yearly, purgeTask)
4354

55+
c.AddFuncWithJobID(gron.Every(1*time.Second), "job-id-1", func() {
56+
fmt.Println("job-id-1 runs every second")
57+
})
58+
c.AddCancelingJob(gron.Every(1*time.Second), &canceledJob{id: "job-id-2"})
59+
c.Start()
60+
61+
time.Sleep(5 * time.Second)
62+
c.Cancel("job-id-1")
63+
time.Sleep(5 * time.Second)
64+
4465
// Stop the scheduler (does not stop any jobs already running).
4566
defer c.Stop()
4667
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
module github.com/roylee0704/gron
1+
module github.com/fakeYanss/gron
22

33
go 1.19

schedule.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"time"
66

7-
"github.com/roylee0704/gron/xtime"
7+
"github.com/fakeYanss/gron/xtime"
88
)
99

1010
// Schedule is the interface that wraps the basic Next method.

schedule_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import (
55
"testing"
66
"time"
77

8-
"github.com/roylee0704/gron/xtime"
8+
"github.com/fakeYanss/gron/xtime"
99
)
1010

1111
func TestPeriodicAtNext(t *testing.T) {

0 commit comments

Comments
 (0)