mirror of
https://github.com/tuna/tunasync.git
synced 2025-04-21 04:42:46 +00:00
commit
9ac3193d50
@ -134,7 +134,7 @@ func main() {
|
||||
app.Name = "tunasync"
|
||||
app.Usage = "tunasync mirror job management tool"
|
||||
app.EnableBashCompletion = true
|
||||
app.Version = "0.1"
|
||||
app.Version = tunasync.Version
|
||||
app.Commands = []cli.Command{
|
||||
{
|
||||
Name: "manager",
|
||||
|
@ -325,7 +325,7 @@ func main() {
|
||||
|
||||
app := cli.NewApp()
|
||||
app.EnableBashCompletion = true
|
||||
app.Version = "0.1"
|
||||
app.Version = tunasync.Version
|
||||
app.Name = "tunasynctl"
|
||||
app.Usage = "control client for tunasync manager"
|
||||
|
||||
|
3
internal/version.go
Normal file
3
internal/version.go
Normal file
@ -0,0 +1,3 @@
|
||||
package internal
|
||||
|
||||
const Version string = "0.2-dev"
|
@ -55,12 +55,20 @@ type globalConfig struct {
|
||||
}
|
||||
|
||||
type managerConfig struct {
|
||||
APIBase string `toml:"api_base"`
|
||||
CACert string `toml:"ca_cert"`
|
||||
ExtraStatusAPIs []string `toml:"extra_status_managers"`
|
||||
APIBase string `toml:"api_base"`
|
||||
// this option overrides the APIBase
|
||||
APIList []string `toml:"api_base_list"`
|
||||
CACert string `toml:"ca_cert"`
|
||||
// Token string `toml:"token"`
|
||||
}
|
||||
|
||||
func (mc managerConfig) APIBaseList() []string {
|
||||
if len(mc.APIList) > 0 {
|
||||
return mc.APIList
|
||||
}
|
||||
return []string{mc.APIBase}
|
||||
}
|
||||
|
||||
type serverConfig struct {
|
||||
Hostname string `toml:"hostname"`
|
||||
Addr string `toml:"listen_addr"`
|
||||
|
@ -386,18 +386,17 @@ func (w *Worker) URL() string {
|
||||
}
|
||||
|
||||
func (w *Worker) registorWorker() {
|
||||
url := fmt.Sprintf(
|
||||
"%s/workers",
|
||||
w.cfg.Manager.APIBase,
|
||||
)
|
||||
|
||||
msg := WorkerStatus{
|
||||
ID: w.Name(),
|
||||
URL: w.URL(),
|
||||
}
|
||||
|
||||
if _, err := PostJSON(url, msg, w.httpClient); err != nil {
|
||||
logger.Errorf("Failed to register worker")
|
||||
for _, root := range w.cfg.Manager.APIBaseList() {
|
||||
url := fmt.Sprintf("%s/workers", root)
|
||||
logger.Debugf("register on manager url: %s", url)
|
||||
if _, err := PostJSON(url, msg, w.httpClient); err != nil {
|
||||
logger.Errorf("Failed to register worker")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -413,12 +412,11 @@ func (w *Worker) updateStatus(job *mirrorJob, jobMsg jobMessage) {
|
||||
ErrorMsg: jobMsg.msg,
|
||||
}
|
||||
|
||||
apiBases := []string{w.cfg.Manager.APIBase}
|
||||
apiBases = append(apiBases, w.cfg.Manager.ExtraStatusAPIs...)
|
||||
for _, root := range apiBases {
|
||||
for _, root := range w.cfg.Manager.APIBaseList() {
|
||||
url := fmt.Sprintf(
|
||||
"%s/workers/%s/jobs/%s", root, w.Name(), jobMsg.name,
|
||||
)
|
||||
logger.Debugf("reporting on manager url: %s", url)
|
||||
if _, err := PostJSON(url, smsg, w.httpClient); err != nil {
|
||||
logger.Errorf("Failed to update mirror(%s) status: %s", jobMsg.name, err.Error())
|
||||
}
|
||||
@ -427,12 +425,9 @@ func (w *Worker) updateStatus(job *mirrorJob, jobMsg jobMessage) {
|
||||
|
||||
func (w *Worker) fetchJobStatus() []MirrorStatus {
|
||||
var mirrorList []MirrorStatus
|
||||
apiBase := w.cfg.Manager.APIBaseList()[0]
|
||||
|
||||
url := fmt.Sprintf(
|
||||
"%s/workers/%s/jobs",
|
||||
w.cfg.Manager.APIBase,
|
||||
w.Name(),
|
||||
)
|
||||
url := fmt.Sprintf("%s/workers/%s/jobs", apiBase, w.Name())
|
||||
|
||||
if _, err := GetJSON(url, &mirrorList, w.httpClient); err != nil {
|
||||
logger.Errorf("Failed to fetch job status: %s", err.Error())
|
||||
|
Loading…
x
Reference in New Issue
Block a user