Skip to content

Commit

Permalink
修改注释
Browse files Browse the repository at this point in the history
  • Loading branch information
domechn committed Nov 21, 2018
1 parent ce331af commit 4580380
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
18 changes: 12 additions & 6 deletions task.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"time"
)

// Task 轮询任务
// Task Polling tasks
type Task struct {
id string

Expand All @@ -21,7 +21,7 @@ type Task struct {
do func()
}

// NewTask 新建轮询任务
// NewTask create a new polling task
func NewTask(t time.Duration, do func()) Tasker {
uid := uuid.NewV4()
return &Task{
Expand All @@ -32,11 +32,12 @@ func NewTask(t time.Duration, do func()) Tasker {
}
}

// ExecuteTime gets the next execution time
func (t *Task) ExecuteTime() time.Time {
return t.executeTime
}

// SetInterval
// SetInterval modify execution interval
func (t *Task) SetInterval(td time.Duration) {
t.interval = td
t.changeExecuteTime(td)
Expand All @@ -46,14 +47,17 @@ func (t *Task) changeExecuteTime(td time.Duration) {
t.executeTime = time.Now().Add(td)
}

// RefreshExecuteTime refresh execution interval
func (t *Task) RefreshExecuteTime() {
t.executeTime = t.executeTime.Add(t.interval)
}

// ID return taskID
func (t *Task) ID() string {
return t.id
}

// Do return Task Function
func (t *Task) Do() func() {
return t.do
}
Expand All @@ -67,7 +71,7 @@ type DayTask struct {
do func()
}

// NewDayTask 新建日任务
// NewDayTask create a new daily task
func NewDayTask(tm string, do func()) (Tasker, error) {
uid := uuid.NewV4()
pt := newTimeParser(dayParseType)
Expand All @@ -85,6 +89,7 @@ func NewDayTask(tm string, do func()) (Tasker, error) {
}, nil
}

// NewDayTasks create new daily tasks
func NewDayTasks(tms []string, do func()) ([]Tasker, error) {
var ts []Tasker
for _, tm := range tms {
Expand Down Expand Up @@ -113,7 +118,7 @@ func (d *DayTask) Do() func() {
return d.do
}

// MonthTask 月任务
// MonthTask create monthly task
type MonthTask struct {
id string

Expand All @@ -122,7 +127,7 @@ type MonthTask struct {
do func()
}

// NewMonthTask 初始化一个每月执行的函数
// NewMonthTask initialize a function that executes each month
func NewMonthTask(tm string, do func()) (Tasker, error) {
uid := uuid.NewV4()
pt := newTimeParser(monthParseType)
Expand All @@ -140,6 +145,7 @@ func NewMonthTask(tm string, do func()) (Tasker, error) {
}, nil
}

// NewMonthTasks initialize a function that executes each month
func NewMonthTasks(tms []string, do func()) ([]Tasker, error) {
var ts []Tasker
for _, tm := range tms {
Expand Down
10 changes: 5 additions & 5 deletions tasker.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ import (
"time"
)

// Tasker 任务接口类
// Tasker interface class
type Tasker interface {

// ID 返回执行函数的ID
// ID Returns the ID of the execution function
ID() string

// ExecuteTime 获取下一次执行时间
// ExecuteTime Gets the next execution time
ExecuteTime() time.Time

// RefreshExecuteTime 刷新执行时间
// RefreshExecuteTime Refresh execution time
RefreshExecuteTime()

// Do 返回执行函数
// Do Return execution function
Do() func()
}

0 comments on commit 4580380

Please sign in to comment.