# cron组件
- 支持cron表达式
- 根据设定的时间规则定时执行函数

## Install

### Prerequisites
- GO >= 1.17

### Using go get
```
go get github.com/mhaya/components/cron@latest
```


## Quick Start
```
import mhayaCron "github.com/mhaya/components/cron"
```


```
// 以组件方式注入到mhaya引擎
func Run(path, env, node string) {
    // 加载profile配置
    mhaya.Configure(path, env, node)
    // cron以组件方式注册到mhaya引擎
    mhayaCron.RegisterComponent()
    // 启动mhaya引擎
    mhaya.Run(false, mhaya.Cluster)
}

// 手工方式启动cron
func main() {
    mhayaCron.Init()

    for i := 0; i <= 23; i++ {
        mhayaCron.AddEveryDayFunc(func() {
            now := mhayaTime.Now()
            mhayaLogger.Infof("每天第%d点%d分%d秒运行", now.Hour(), now.Minute(), now.Second())
        }, i, 12, 34)
        mhayaLogger.Infof("添加 每天第%d点执行的定时器", i)
    }

    for i := 0; i <= 59; i++ {
        mhayaCron.AddEveryHourFunc(func() {
            mhayaLogger.Infof("每小时第%d分执行一次", mhayaTime.Now().Minute())
        }, i, 0)
        mhayaLogger.Infof("添加 每小时第%d分的定时器", i)
    }

    mhayaCron.Run()
}

```

## example
- [示例代码跳转](cron_test.go)