123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- package dep
- import (
- "kpt-pasture/config"
- "kpt-pasture/module/crontab"
- "gitee.com/xuyiping_admin/pkg/logger/zaplog"
- "go.uber.org/zap"
- "go.uber.org/dig"
- "gitee.com/xuyiping_admin/pkg/cron"
- prom "github.com/prometheus/client_golang/prometheus"
- )
- var DataCenterCrontabCounterVec = prom.NewCounterVec(
- prom.CounterOpts{
- Namespace: "kpt-pasture",
- Subsystem: "crontab",
- Name: "crontab",
- },
- []string{"name"},
- )
- func DICrontabService() (out *cron.Crontab) {
- container := DI()
- if err := container.Provide(EntryCrontab); err != nil {
- panic(err)
- }
- if err := container.Invoke(func(c *cron.Crontab) { out = c }); err != nil {
- panic(err)
- }
- return
- }
- // CrontabDependency 依赖注入结构体
- type CrontabDependency struct {
- dig.In
- CrontabHub crontab.Crontab // 定时任务
- }
- func EntryCrontab(dependency CrontabDependency) *cron.Crontab {
- cfg := config.Options()
- cs := cfg.CronSetting
- newCrontab := cron.NewCrontab(DataCenterCrontabCounterVec)
- err := newCrontab.Bind("indicators", cs.Indicators, dependency.CrontabHub.Indicators)
- if err != nil {
- panic(err)
- }
- err = newCrontab.Bind("UpdateCowInfo", cs.UpdateCowInfo, dependency.CrontabHub.UpdateCowInfo)
- if err != nil {
- panic(err)
- }
- err = newCrontab.Bind("ImmunizationPlan", cs.ImmunizationPlan, dependency.CrontabHub.ImmunizationPlan)
- if err != nil {
- panic(err)
- }
- err = newCrontab.Bind("SameTimePlan", cs.SameTimePlan, dependency.CrontabHub.SameTimePlan)
- if err != nil {
- panic(err)
- }
- err = newCrontab.Bind("UpdateSameTime", cs.UpdateSameTime, dependency.CrontabHub.UpdateSameTime)
- if err != nil {
- panic(err)
- }
- err = newCrontab.Bind("SystemBasicCrontab", cs.SystemBasicCrontab, dependency.CrontabHub.SystemBasicCrontab)
- if err != nil {
- panic(err)
- }
- err = newCrontab.Bind("DeleteOldOriginal", cs.DeleteOldOriginal, dependency.CrontabHub.DeleteOldOriginal)
- if err != nil {
- panic(err)
- }
- err = newCrontab.Bind("UpdateCowEstrus", cs.NeckRingEstrus, dependency.CrontabHub.UpdateCowEstrus)
- if err != nil {
- zaplog.Error("EntryCrontab", zap.Any("UpdateCowEstrus", err))
- panic(err)
- }
- err = newCrontab.Bind("NeckRingCalculate", cs.NeckRingCalculate, dependency.CrontabHub.NeckRingCalculate)
- if err != nil {
- zaplog.Error("EntryCrontab", zap.Any("NeckRingCalculate", err))
- panic(err)
- }
- err = newCrontab.Bind("NeckRingMerge", cs.NeckRingMerge, dependency.CrontabHub.NeckRingOriginalMergeData)
- if err != nil {
- zaplog.Error("EntryCrontab", zap.Any("NeckRingOriginalMergeData", err))
- panic(err)
- }
- /*err = newCrontab.Bind("GenerateWorkOrder", cs.GenerateWorkOrder, dependency.CrontabHub.GenerateAsynqWorkOrder)
- if err != nil {
- panic(err)
- }
- err = newCrontab.Bind("CowPregnant", cs.CowPregnant, dependency.CrontabHub.CowPregnant)
- if err != nil {
- panic(err)
- }*/
- return newCrontab
- }
|