-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(greet): Add timed tasks to synchronize data
- Loading branch information
Northes
committed
Dec 20, 2022
1 parent
1816519
commit 197b30e
Showing
8 changed files
with
65 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package cron | ||
|
||
import ( | ||
"apihut-server/config" | ||
"apihut-server/dao/bleve" | ||
"apihut-server/logger" | ||
|
||
"github.com/robfig/cron/v3" | ||
"go.uber.org/zap" | ||
) | ||
|
||
func Init() { | ||
c := cron.New() | ||
|
||
// 一句招呼数据同步 | ||
_, _ = c.AddFunc(config.Conf.Bleve.SyncCron, func() { | ||
logger.L().Info("【定时任务】开始同步一句招呼数据...") | ||
err := bleve.SyncFromDB() | ||
if err != nil { | ||
logger.L().Error("【定时任务】同步一句招呼数据失败", zap.Error(err)) | ||
return | ||
} | ||
logger.L().Info("【定时任务】同步一句招呼数据成功!") | ||
}) | ||
|
||
c.Start() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package gen | ||
|
||
import ( | ||
"crypto/md5" | ||
"encoding/hex" | ||
) | ||
|
||
func MD5(str []byte) string { | ||
h := md5.New() | ||
h.Write(str) | ||
return hex.EncodeToString(h.Sum(nil)) | ||
} |