forked from shunfei/cronsun
-
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.
- Loading branch information
Showing
4 changed files
with
56 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
{ | ||
"Proc": "/cronsun/proc", | ||
"Cmd": "cronsun/cmd", | ||
"Log": "@extend:log.json", | ||
"Etcd": "@extend:etcd.json" | ||
} |
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 |
---|---|---|
@@ -1,25 +1,58 @@ | ||
package node | ||
|
||
import ( | ||
"os" | ||
|
||
client "github.com/coreos/etcd/clientv3" | ||
|
||
"sunteng/commons/util" | ||
) | ||
|
||
// Node 执行 cron 命令服务的结构体 | ||
type Node struct { | ||
*client.Client | ||
|
||
IP string | ||
PID int | ||
} | ||
|
||
func NewNode(cfg client.Config) *Node { | ||
return &Node{} | ||
func NewNode(cfg client.Config) (n *Node, err error) { | ||
ip, err := util.GetLocalIP() | ||
if err != nil { | ||
return | ||
} | ||
|
||
cli, err := client.New(cfg) | ||
if err != nil { | ||
return | ||
} | ||
|
||
n = &Node{ | ||
Client: cli, | ||
|
||
IP: ip.String(), | ||
PID: os.Getpid(), | ||
} | ||
return | ||
} | ||
|
||
// 注册到 /cronsun/proc/xx | ||
func (n *Node) Register() { | ||
|
||
func (n *Node) Register() error { | ||
return nil | ||
} | ||
|
||
// 更新 /cronsun/proc/xx/time | ||
// 用于检查 node 是否存活 | ||
func (n *Node) Heartbeat() { | ||
|
||
} | ||
|
||
// 启动服务 | ||
func (n *Node) Run() { | ||
|
||
} | ||
|
||
// 启动服务 | ||
func (n *Node) Stop(i interface{}) { | ||
n.Client.Close() | ||
} |