Esempio n. 1
0
// NewGroup creates Group instance
func NewGroup(tasks ...*signatures.TaskSignature) *Group {
	// Generate a group UUID
	groupUUID := uuid.New()

	// Auto generate task UUIDs
	// Group tasks by common UUID
	for _, task := range tasks {
		task.UUID = fmt.Sprintf("task_%v", uuid.New())
		task.GroupUUID = fmt.Sprintf("group_%v", groupUUID)
		task.GroupTaskCount = len(tasks)
	}

	return &Group{Tasks: tasks}
}
Esempio n. 2
0
// NewChord creates Chord instance
func NewChord(group *Group, callback *signatures.TaskSignature) *Chord {
	// Generate a UUID for the chord callback
	callback.UUID = fmt.Sprintf("chord_%v", uuid.New())

	// Add a chord callback to all tasks
	for _, task := range group.Tasks {
		task.ChordCallback = callback
	}

	return &Chord{Group: group, Callback: callback}
}
Esempio n. 3
0
// NewChain creates Chain instance
func NewChain(tasks ...*signatures.TaskSignature) *Chain {
	for i := len(tasks) - 1; i > 0; i-- {
		if i > 0 {
			tasks[i-1].OnSuccess = []*signatures.TaskSignature{tasks[i]}
		}
	}

	chain := &Chain{Tasks: tasks}

	// Auto generate task UUIDs
	for _, task := range chain.Tasks {
		task.UUID = fmt.Sprintf("task_%v", uuid.New())
	}

	return chain
}
Esempio n. 4
0
// SendTask publishes a task to the default queue
func (server *Server) SendTask(signature *signatures.TaskSignature) (*backends.AsyncResult, error) {
	// Auto generate a UUID if not set already
	if signature.UUID == "" {
		signature.UUID = fmt.Sprintf("task_%v", uuid.New())
	}

	// Set initial task state to PENDING
	if err := server.backend.SetStatePending(signature); err != nil {
		return nil, fmt.Errorf("Set State Pending: %v", err)
	}

	if err := server.broker.Publish(signature); err != nil {
		return nil, fmt.Errorf("Publish Message: %v", err)
	}

	return backends.NewAsyncResult(signature, server.backend), nil
}