mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-19 17:24:26 +08:00
support scheduled transaction (#2)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package cron
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-co-op/gocron/v2"
|
||||
@@ -22,6 +23,11 @@ type CronJobFixedHourPeriod struct {
|
||||
Hour uint32
|
||||
}
|
||||
|
||||
// CronJobEvery15MinutesPeriod represents the period of execution at every 15 minutes
|
||||
type CronJobEvery15MinutesPeriod struct {
|
||||
Second uint32
|
||||
}
|
||||
|
||||
// CronJobFixedTimePeriod represents the period of execution at fixed time
|
||||
type CronJobFixedTimePeriod struct {
|
||||
Time time.Time
|
||||
@@ -52,6 +58,16 @@ func (p CronJobFixedHourPeriod) ToJobDefinition() gocron.JobDefinition {
|
||||
)
|
||||
}
|
||||
|
||||
// GetInterval returns the interval time of the period of CronJobEvery15MinutesPeriod
|
||||
func (p CronJobEvery15MinutesPeriod) GetInterval() time.Duration {
|
||||
return 15 * time.Minute
|
||||
}
|
||||
|
||||
// ToJobDefinition returns the gocron job definition of the period of CronJobEvery15MinutesPeriod
|
||||
func (p CronJobEvery15MinutesPeriod) ToJobDefinition() gocron.JobDefinition {
|
||||
return gocron.CronJob(fmt.Sprintf("%d */15 * * * *", p.Second), true)
|
||||
}
|
||||
|
||||
// GetInterval returns the interval time of the period of CronJobFixedTimePeriod
|
||||
func (p CronJobFixedTimePeriod) GetInterval() time.Duration {
|
||||
return 0
|
||||
|
||||
Reference in New Issue
Block a user