-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 04c0dcd
Showing
10 changed files
with
963 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
.idea/ | ||
go-quartz |
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 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2019 reugn | ||
|
||
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,42 @@ | ||
# go-quartz | ||
A go scheduling library | ||
|
||
## About | ||
Inspired by [quartz](https://github.com/quartz-scheduler/quartz) java scheduler. | ||
|
||
### Library building blocks | ||
Job interface. Should be implemented by custom jobs for further scheduling | ||
```go | ||
type Job interface { | ||
Execute() | ||
Description() string | ||
} | ||
``` | ||
Scheduler interface | ||
```go | ||
type Scheduler interface { | ||
Start() | ||
ScheduleJob(job Job, trigger Trigger) error | ||
Stop() | ||
} | ||
``` | ||
Implemented Schedulers | ||
- StdScheduler | ||
|
||
Trigger interface | ||
```go | ||
type Trigger interface { | ||
NextFireTime(prev int64) (int64, error) | ||
Description() string | ||
} | ||
``` | ||
Implemented Triggers | ||
- CronTrigger | ||
- SimpleTrigger | ||
- RunOnceTrigger | ||
|
||
## Examples | ||
Could be found in examples directory. | ||
|
||
## License | ||
Licensed under the MIT License. |
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,33 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
|
||
"go-quartz/quartz" | ||
) | ||
|
||
//implements quartz.Job interface | ||
type PrintJob struct { | ||
desc string | ||
} | ||
|
||
func (pj PrintJob) Description() string { | ||
return pj.desc | ||
} | ||
|
||
func (pj PrintJob) Execute() { | ||
fmt.Println("Executing " + pj.Description()) | ||
} | ||
|
||
//demo main | ||
func main() { | ||
sched := quartz.NewStdScheduler() | ||
sched.Start() | ||
sched.ScheduleJob(&PrintJob{"Ad hoc Job"}, quartz.NewRunOnceTrigger(time.Second*5)) | ||
sched.ScheduleJob(&PrintJob{"First job"}, quartz.NewSimpleTrigger(time.Second*12)) | ||
sched.ScheduleJob(&PrintJob{"Second job"}, quartz.NewSimpleTrigger(time.Second*6)) | ||
sched.ScheduleJob(&PrintJob{"Third job"}, quartz.NewSimpleTrigger(time.Second*3)) | ||
time.Sleep(time.Second * 15) | ||
sched.Stop() | ||
} |
Oops, something went wrong.