feat: 三个三方IM定时任务的统一添加 (#62)
This commit is contained in:
parent
f46c19510d
commit
7e910bf5fa
|
@ -118,3 +118,4 @@ feishu:
|
||||||
flag: "feishu" # 作为飞书在平台的标识
|
flag: "feishu" # 作为飞书在平台的标识
|
||||||
app-id: "xxxxxxx" # 飞书的app-id
|
app-id: "xxxxxxx" # 飞书的app-id
|
||||||
app-secret: "xxxxxxxxxxx" # 飞书的app-secret
|
app-secret: "xxxxxxxxxxx" # 飞书的app-secret
|
||||||
|
enable-sync: false # 是否开启定时同步飞书的任务
|
|
@ -165,10 +165,12 @@ type WeComConfig struct {
|
||||||
CorpID string `mapstructure:"corp-id" json:"corpId"`
|
CorpID string `mapstructure:"corp-id" json:"corpId"`
|
||||||
AgentID int `mapstructure:"agent-id" json:"agentId"`
|
AgentID int `mapstructure:"agent-id" json:"agentId"`
|
||||||
CorpSecret string `mapstructure:"corp-secret" json:"corpSecret"`
|
CorpSecret string `mapstructure:"corp-secret" json:"corpSecret"`
|
||||||
|
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type FeiShuConfig struct {
|
type FeiShuConfig struct {
|
||||||
Flag string `mapstructure:"flag" json:"flag"`
|
Flag string `mapstructure:"flag" json:"flag"`
|
||||||
AppID string `mapstructure:"app-id" json:"appId"`
|
AppID string `mapstructure:"app-id" json:"appId"`
|
||||||
AppSecret string `mapstructure:"app-secret" json:"appSecret"`
|
AppSecret string `mapstructure:"app-secret" json:"appSecret"`
|
||||||
|
EnableSync bool `mapstructure:"enable-sync" json:"enableSync"`
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,10 +5,12 @@ import (
|
||||||
|
|
||||||
"github.com/eryajf/go-ldap-admin/config"
|
"github.com/eryajf/go-ldap-admin/config"
|
||||||
"github.com/eryajf/go-ldap-admin/model"
|
"github.com/eryajf/go-ldap-admin/model"
|
||||||
|
"github.com/eryajf/go-ldap-admin/public/common"
|
||||||
"github.com/eryajf/go-ldap-admin/public/tools"
|
"github.com/eryajf/go-ldap-admin/public/tools"
|
||||||
"github.com/eryajf/go-ldap-admin/service/ildap"
|
"github.com/eryajf/go-ldap-admin/service/ildap"
|
||||||
"github.com/eryajf/go-ldap-admin/service/isql"
|
"github.com/eryajf/go-ldap-admin/service/isql"
|
||||||
jsoniter "github.com/json-iterator/go"
|
jsoniter "github.com/json-iterator/go"
|
||||||
|
"github.com/robfig/cron/v3"
|
||||||
"github.com/tidwall/gjson"
|
"github.com/tidwall/gjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -304,3 +306,61 @@ func ConvertUserData(flag string, remoteData []map[string]interface{}) (users []
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func InitCron() {
|
||||||
|
c := cron.New(cron.WithSeconds())
|
||||||
|
|
||||||
|
if config.Conf.DingTalk.EnableSync {
|
||||||
|
//启动定时任务
|
||||||
|
_, err := c.AddFunc("0 1 5 * * *", func() {
|
||||||
|
common.Log.Info("每天凌晨5点1分0秒执行一次同步钉钉部门信息到ldap")
|
||||||
|
DingTalk.SyncDingTalkDepts(nil, nil)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
common.Log.Errorf("启动同步部门的定时任务失败: %v", err)
|
||||||
|
}
|
||||||
|
//每天凌晨1点执行一次
|
||||||
|
_, err = c.AddFunc("0 30 5 * * *", func() {
|
||||||
|
common.Log.Info("每天凌晨5点30分执行一次同步钉钉用户信息到ldap")
|
||||||
|
DingTalk.SyncDingTalkUsers(nil, nil)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
common.Log.Errorf("启动同步用户的定时任务失败: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if config.Conf.WeCom.EnableSync {
|
||||||
|
_, err := c.AddFunc("0 1 5 * * *", func() {
|
||||||
|
common.Log.Info("每天凌晨5点1分0秒执行一次同步企业微信部门信息到ldap")
|
||||||
|
WeCom.SyncWeComDepts(nil, nil)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
common.Log.Errorf("启动同步部门的定时任务失败: %v", err)
|
||||||
|
}
|
||||||
|
//每天凌晨1点执行一次
|
||||||
|
_, err = c.AddFunc("0 30 5 * * *", func() {
|
||||||
|
common.Log.Info("每天凌晨5点30分执行一次同步企业微信用户信息到ldap")
|
||||||
|
WeCom.SyncWeComUsers(nil, nil)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
common.Log.Errorf("启动同步用户的定时任务失败: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if config.Conf.FeiShu.EnableSync {
|
||||||
|
_, err := c.AddFunc("0 1 5 * * *", func() {
|
||||||
|
common.Log.Info("每天凌晨5点1分0秒执行一次同步飞书部门信息到ldap")
|
||||||
|
FeiShu.SyncFeiShuDepts(nil, nil)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
common.Log.Errorf("启动同步部门的定时任务失败: %v", err)
|
||||||
|
}
|
||||||
|
//每天凌晨1点执行一次
|
||||||
|
_, err = c.AddFunc("0 30 5 * * *", func() {
|
||||||
|
common.Log.Info("每天凌晨5点30分执行一次同步飞书用户信息到ldap")
|
||||||
|
FeiShu.SyncFeiShuUsers(nil, nil)
|
||||||
|
})
|
||||||
|
if err != nil {
|
||||||
|
common.Log.Errorf("启动同步用户的定时任务失败: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
c.Start()
|
||||||
|
}
|
||||||
|
|
22
main.go
22
main.go
|
@ -9,7 +9,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/eryajf/go-ldap-admin/logic"
|
"github.com/eryajf/go-ldap-admin/logic"
|
||||||
"github.com/robfig/cron/v3"
|
|
||||||
|
|
||||||
"github.com/eryajf/go-ldap-admin/config"
|
"github.com/eryajf/go-ldap-admin/config"
|
||||||
"github.com/eryajf/go-ldap-admin/middleware"
|
"github.com/eryajf/go-ldap-admin/middleware"
|
||||||
|
@ -65,26 +64,9 @@ func main() {
|
||||||
common.Log.Fatalf("listen: %s\n", err)
|
common.Log.Fatalf("listen: %s\n", err)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
if config.Conf.DingTalk.EnableSync {
|
|
||||||
// 启动定时任务
|
// 启动定时任务
|
||||||
c := cron.New(cron.WithSeconds())
|
logic.InitCron()
|
||||||
_, err := c.AddFunc("0 1 0 * * *", func() {
|
|
||||||
common.Log.Info("每天0点1分0秒执行一次同步钉钉部门和用户信息到ldap")
|
|
||||||
logic.DingTalk.SyncDingTalkDepts(nil, nil)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
common.Log.Errorf("启动同步部门的定时任务失败: %v", err)
|
|
||||||
}
|
|
||||||
//每天凌晨1点执行一次
|
|
||||||
_, err = c.AddFunc("0 15 0 * * *", func() {
|
|
||||||
common.Log.Info("每天凌晨00点15分执行一次同步钉钉部门和用户信息到ldap")
|
|
||||||
logic.DingTalk.SyncDingTalkUsers(nil, nil)
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
common.Log.Errorf("启动同步用户的定时任务失败: %v", err)
|
|
||||||
}
|
|
||||||
c.Start()
|
|
||||||
}
|
|
||||||
|
|
||||||
common.Log.Info(fmt.Sprintf("Server is running at %s:%d/%s", host, port, config.Conf.System.UrlPathPrefix))
|
common.Log.Info(fmt.Sprintf("Server is running at %s:%d/%s", host, port, config.Conf.System.UrlPathPrefix))
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue