Merge pull request #116 from shunfei/develop

bugfixed
pull/119/head
QLeelulu 6 years ago committed by GitHub
commit 7c35c9ce01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -3,6 +3,11 @@
"127.0.0.1:27017" "127.0.0.1:27017"
], ],
"Database": "cronsun", "Database": "cronsun",
"#AuthSource": "AuthSource Specify the database name associated with the users credentials.",
"#AuthSource": "AuthSource defaults to the cronsun's Database.",
"#AuthSource": "If connect mongodb like './bin/mongo mytest -u "test" -p "123" --authenticationDatabase admin' ,",
"#AuthSource": "the AuthSource is 'admin'. ",
"AuthSource": "",
"UserName": "", "UserName": "",
"Password": "", "Password": "",
"#Timeout": "connect timeout duration/second", "#Timeout": "connect timeout duration/second",

@ -1,6 +1,7 @@
package db package db
import ( import (
"net/url"
"strings" "strings"
"time" "time"
@ -10,6 +11,9 @@ import (
type Config struct { type Config struct {
Hosts []string Hosts []string
// AuthSource Specify the database name associated with the users credentials.
// authSource defaults to the database specified in the connection string.
AuthSource string
UserName string UserName string
Password string Password string
Database string Database string
@ -29,17 +33,22 @@ func NewMdb(c *Config) (*Mdb, error) {
} }
func (m *Mdb) connect() error { func (m *Mdb) connect() error {
// url: [mongodb://][user:pass@]host1[:port1][,host2[:port2],...][/database][?options] // connectionString: [mongodb://][user:pass@]host1[:port1][,host2[:port2],...][/database][?options]
url := strings.Join(m.Config.Hosts, ",") // via: https://docs.mongodb.com/manual/reference/connection-string/
connectionString := strings.Join(m.Config.Hosts, ",")
if len(m.Config.UserName) > 0 && len(m.Config.Password) > 0 { if len(m.Config.UserName) > 0 && len(m.Config.Password) > 0 {
url = m.Config.UserName + ":" + m.Config.Password + "@" + url connectionString = m.Config.UserName + ":" + url.QueryEscape(m.Config.Password) + "@" + connectionString
} }
if len(m.Config.Database) > 0 { if len(m.Config.Database) > 0 {
url += "/" + m.Config.Database connectionString += "/" + m.Config.Database
} }
session, err := mgo.DialWithTimeout(url, m.Config.Timeout) if len(m.Config.AuthSource) > 0 {
connectionString += "?authSource=" + m.Config.AuthSource
}
session, err := mgo.DialWithTimeout(connectionString, m.Config.Timeout)
if err != nil { if err != nil {
return err return err
} }

@ -304,23 +304,32 @@ func (n *Node) addGroup(g *cronsun.Group) {
} }
func (n *Node) delGroup(id string) { func (n *Node) delGroup(id string) {
delete(n.groups, id) // delete job first
n.link.delGroup(id) defer n.link.delGroup(id)
defer delete(n.groups, id)
job, ok := n.jobs[id] jobLinks := n.link[id]
if len(jobLinks) == 0 {
return
}
for jID := range jobLinks {
job, ok := n.jobs[jID]
// 之前此任务没有在当前结点执行 // 之前此任务没有在当前结点执行
if !ok { if !ok {
return continue
} }
cmds := job.Cmds(n.ID, n.groups) cmds := job.Cmds(n.ID, n.groups)
if len(cmds) == 0 { if len(cmds) == 0 {
return continue
} }
for _, cmd := range cmds { for _, cmd := range cmds {
n.delCmd(cmd) n.delCmd(cmd)
} }
}
return return
} }

Loading…
Cancel
Save