Example #1
0
func Update(u *rpc.UpdateArgs) JSON.Type {
	lock.Lock()
	defer lock.Unlock()

	results := JSON.Type{}

	helper.AsyncMap(u.FileList, func(key, value interface{}) bool {
		var err error
		p := key.(string)
		filePath := "/" + p
		action := value.(int)

		//添加和更新直接下载覆盖
		if action == actionEnum.Add || action == actionEnum.Update {

			fileUrl := u.ResPath + filePath
			//下载错误
			err = utils.Download(fileUrl, path.Join(deployPath, filePath))
		} else if action == actionEnum.Del {
			//删除文件错误
			utils.RemovePath(path.Join(deployPath, filePath))
		}

		if err != nil {
			results[p] = err.Error()
		} else {
			results[p] = true
		}

		return false
	})

	return results
}
Example #2
0
func init() {
	bootstrap.Register(func() {
		StartTask()
		helper.AsyncMap(taskList, func(key, value interface{}) bool {
			value.(*Task).Watch()
			return false
		})
	})
}
Example #3
0
//多终端Rpc调用
//TODO
//队列调用,最大同时调用数
func BatchCallRpc(clients HostMap, method string, params ...rpc.RpcInterface) JSON.Type {
	results := JSON.Type{}
	helper.AsyncMap(clients, func(key, value interface{}) bool {
		c := value.(*HostClient)
		result, err := c.CallRpc(method, params...)
		if err != nil {
			results[helper.Itoa64(c.Id)] = helper.Error(err)
		} else {
			results[helper.Itoa64(c.Id)] = result
		}
		return false
	})
	return results
}
Example #4
0
//参数为空或者是[0]代表获取所有主机
func List(ids ...[]int64) HostMap {
	if len(ids) == 1 && len(ids[0]) > 0 && ids[0][0] != 0 {
		list := HostMap{}
		idList := ids[0]
		helper.AsyncMap(idList, func(key, value interface{}) bool {
			if c := FindFromCache(value.(int64)); c != nil {
				list[c.Id] = c
			}
			return false
		})
		return list
	}

	return hostMap
}
Example #5
0
/*
主动推送方法,将会根据method不停向客户端推送内容
*/
func loopPushFrame() {
	for {
		syncLock.Lock()
		helper.AsyncMap(clients, func(key, value interface{}) bool {
			client := value.(*socketClient)
			if client != nil && client.message != nil {
				if method := client.message.Method; method != "" {
					client.out <- &Message{method, onEmitCallback[method]()}
				}
			}
			return false
		})
		syncLock.Unlock()
		time.Sleep(3 * time.Second)
	}
}
Example #6
0
func Refresh() {
	helper.AsyncMap(hostMap, func(key, value interface{}) bool {
		c := value.(*HostClient)
		s := c.GetStatus()
		if s == status.Die {
			c.Proc.CPUPercent = 0
			c.Proc.MEMPercent = 0
		} else if c.Status == status.Die && s == status.Alive {
			c.ReportMeUsage()
		}
		if c.Status == status.Busy && s == status.Alive {

		} else {
			c.Status = s
		}
		return false
	})
}
Example #7
0
func init() {
	task.New("Heartbeat", func(this *task.Task) interface{} {
		Refresh()
		return nil
	})

	updating := false

	task.New("client.UpdateHostUnDeployList", func(this *task.Task) interface{} {

		if updating {
			return nil
		}

		updating = true

		defer func() {
			this.Enable = false
			updating = false
		}()

		webSocket.BroadCastAll(&webSocket.Message{
			Method: "syncDeployList",
		})

		if master.UnDeployList != nil {
			result := map[int64]error{}
			helper.AsyncMap(hostMap, func(key, value interface{}) bool {
				c := value.(*HostClient)
				err := c.UpdateUnDeployList(&master.UnDeployList)
				result[c.Id] = err
				return false
			})
			webSocket.BroadCastAll(&webSocket.Message{
				Method: "syncDeployList",
				Params: result,
			})
		}
		return nil
	})
}