Beispiel #1
0
func (l *ExampleListener) OnJoin(zk *zkutil.ZooKeeper) {
	log.Println("Joining!")
	// Create an assigned task for this node as soon as it joins...
	data := make(map[string]interface{})
	// assign this task specifically to this node
	// data["example"] = l.config.NodeId
	donut.CreateTask("example", zk.Conn, "task-"+l.config.NodeId, data)
	go func() {
		// only do this task for 5 seconds
		time.Sleep(60 * time.Second)
		donut.CompleteTask("example", zk.Conn, "task-"+l.config.NodeId)
	}()
}
Beispiel #2
0
func (c *Ctl) addTask(cluster, taskId, assign string, data map[string]interface{}) error {
	m := make(map[string]interface{})
	for k, v := range data {
		if k == cluster {
			return errors.New("Found reserved key %s in data map: " + k)
		}
		m[k] = v
	}
	if assign != "" {
		m[cluster] = assign
	}

	return donut.CreateTask(cluster, c.zk, taskId, data)
}