division변경시 서비스에 통지
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
package core
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
"path"
|
||||
@ -312,15 +314,26 @@ func (mg *Maingate) watchServiceCollection(parentctx context.Context, serveMux *
|
||||
atomic.SwapPointer(&old.wl.emailptr, data.Service.wl.emailptr)
|
||||
|
||||
old.Divisions = data.Service.Divisions
|
||||
} else if !data.Service.Closed {
|
||||
if err := data.Service.prepare(mg); err != nil {
|
||||
logger.Error("service cannot be prepared :", data.Service, err)
|
||||
for _, div := range old.Divisions {
|
||||
var req *http.Request
|
||||
if div.State == DivisionState_Maintenance {
|
||||
bt, _ := json.Marshal(div.Maintenance)
|
||||
req, _ = http.NewRequest("POST", div.Url+"/maingate", bytes.NewBuffer(bt))
|
||||
} else {
|
||||
req, _ = http.NewRequest("POST", div.Url+"/maingate", nil)
|
||||
}
|
||||
|
||||
// MG-X-API-TOKEN
|
||||
req.Header.Add("MG-X-API-TOKEN", old.ServerApiTokens[0].Hex())
|
||||
if resp, err := http.DefaultClient.Do(req); err == nil {
|
||||
resp.Body.Close()
|
||||
}
|
||||
}
|
||||
} else if !data.Service.Closed {
|
||||
logger.Println("service is on the board! :", data.Service)
|
||||
mg.services.add(data.Service)
|
||||
serveMux.Handle(common.MakeHttpHandlerPattern(prefix, data.Service.ServiceCode, "/"), data.Service)
|
||||
}
|
||||
}
|
||||
case "delete":
|
||||
if deleted := mg.services.remove(data.DocumentKey.Id); deleted != nil {
|
||||
logger.Println("service is closed :", data.Service)
|
||||
|
||||
Reference in New Issue
Block a user