代码拉取完成,页面将自动刷新
package scheduler
import (
"errors"
"fmt"
"time"
)
// Trigger represents the mechanism by which Jobs are scheduled.
type Trigger interface {
Type() string
// NextFireTime returns the next time at which the Trigger is scheduled to fire.
NextFireTime(prev int64) (int64, error)
// Description returns the description of the Trigger.
Description() string
}
// SimpleTrigger implements the quartz.Trigger interface; uses a fixed interval.
type SimpleTrigger struct {
Interval time.Duration
}
// Verify SimpleTrigger satisfies the Trigger interface.
var _ Trigger = (*SimpleTrigger)(nil)
// NewSimpleTrigger returns a new SimpleTrigger using the given interval.
func NewSimpleTrigger(interval time.Duration) *SimpleTrigger {
return &SimpleTrigger{
Interval: interval,
}
}
func (st *SimpleTrigger) Type() string {
return "simple"
}
// NextFireTime returns the next time at which the SimpleTrigger is scheduled to fire.
func (st *SimpleTrigger) NextFireTime(prev int64) (int64, error) {
next := prev + st.Interval.Nanoseconds()
return next, nil
}
// Description returns the description of the trigger.
func (st *SimpleTrigger) Description() string {
return fmt.Sprintf("SimpleTrigger with interval: %d", st.Interval)
}
// OnceTrigger implements the quartz.Trigger interface.
// This type of Trigger can only be fired once and will expire immediately.
type OnceTrigger struct {
Delay time.Duration
expired bool
}
// Verify OnceTrigger satisfies the Trigger interface.
var _ Trigger = (*OnceTrigger)(nil)
// NewOnceTrigger returns a new OnceTrigger with the given delay time.
func NewOnceTrigger(delay time.Duration) *OnceTrigger {
return &OnceTrigger{
Delay: delay,
expired: false,
}
}
func (tr *OnceTrigger) Type() string {
return "once"
}
// NextFireTime returns the next time at which the OnceTrigger is scheduled to fire.
// Sets expired to true afterwards.
func (tr *OnceTrigger) NextFireTime(prev int64) (int64, error) {
if !tr.expired {
next := prev + tr.Delay.Nanoseconds()
tr.expired = true
return next, nil
}
return 0, errors.New("RunOnce trigger is expired")
}
// Description returns the description of the trigger.
func (tr *OnceTrigger) Description() string {
status := "valid"
if tr.expired {
status = "expired"
}
return fmt.Sprintf("OnceTrigger (%s).", status)
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。