예제 #1
0
func _testSendChain(server *machinery.Server, t *testing.T) {
	tasks := _getTasks()

	chain := machinery.NewChain(&tasks[1], &tasks[2], &tasks[3])
	chainAsyncResult, err := server.SendChain(chain)
	if err != nil {
		t.Error(err)
	}

	result, err := chainAsyncResult.Get()
	if err != nil {
		t.Error(err)
	}

	if result.Interface() != int64(60) {
		t.Errorf(
			"result = %v(%v), want int64(60)",
			result.Type().String(),
			result.Interface(),
		)
	}
}
예제 #2
0
파일: send.go 프로젝트: ddmd2015/machinery
func main() {
	/*
	 * First, let's try sending a single task
	 */

	asyncResult, err := server.SendTask(&task0)
	errors.Fail(err, "Could not send task")

	result, err := asyncResult.Get()
	errors.Fail(err, "Getting task state failed with error")
	fmt.Printf("%v\n", result.Interface())

	/*
	 * Now let's explore ways of sending multiple tasks
	 */

	// Now let's try a parallel execution
	group := machinery.NewGroup(&task1, &task2, &task3)
	asyncResults, err := server.SendGroup(group)
	errors.Fail(err, "Could not send group")

	for _, asyncResult := range asyncResults {
		result, err = asyncResult.Get()
		errors.Fail(err, "Getting task state failed with error")
		fmt.Printf("%v\n", result.Interface())
	}

	// Now let's try chaining task results
	chain := machinery.NewChain(&task1, &task2, &task3)
	chainAsyncResult, err := server.SendChain(chain)
	errors.Fail(err, "Could not send chain")

	result, err = chainAsyncResult.Get()
	errors.Fail(err, "Getting chain result failed with error")
	fmt.Printf("%v\n", result.Interface())
}
예제 #3
0
func main() {
	/*
	 * First, let's try sending a single task
	 */
	initTasks()
	fmt.Println("Single task:")

	asyncResult, err := server.SendTask(&task0)
	errors.Fail(err, "Could not send task")

	result, err := asyncResult.Get()
	errors.Fail(err, "Getting task state failed with error")
	fmt.Printf("1 + 1 = %v\n", result.Interface())

	/*
	 * Now let's explore ways of sending multiple tasks
	 */

	// Now let's try a parallel execution
	initTasks()
	fmt.Println("Group of tasks (parallel execution):")

	group := machinery.NewGroup(&task0, &task1, &task2)
	asyncResults, err := server.SendGroup(group)
	errors.Fail(err, "Could not send group")

	for _, asyncResult := range asyncResults {
		result, err = asyncResult.Get()
		errors.Fail(err, "Getting task state failed with error")
		fmt.Printf(
			"%v + %v = %v\n",
			asyncResult.Signature.Args[0].Value,
			asyncResult.Signature.Args[1].Value,
			result.Interface(),
		)
	}

	// Now let's try a group with a chord
	initTasks()
	fmt.Println("Group of tasks with a callback (chord):")

	group = machinery.NewGroup(&task0, &task1, &task2)
	chord := machinery.NewChord(group, &task4)
	chordAsyncResult, err := server.SendChord(chord)
	errors.Fail(err, "Could not send chord")

	result, err = chordAsyncResult.Get()
	errors.Fail(err, "Getting task state failed with error")
	fmt.Printf("(1 + 1) * (2 + 2) * (5 + 6) = %v\n", result.Interface())

	// Now let's try chaining task results
	initTasks()
	fmt.Println("Chain of tasks:")

	chain := machinery.NewChain(&task0, &task1, &task2, &task3)
	chainAsyncResult, err := server.SendChain(chain)
	errors.Fail(err, "Could not send chain")

	result, err = chainAsyncResult.Get()
	errors.Fail(err, "Getting chain result failed with error")
	fmt.Printf("(((1 + 1) + (2 + 2)) + (5 + 6)) * 4 = %v\n", result.Interface())
}
예제 #4
0
파일: send.go 프로젝트: wmydz1/machinery
func main() {
	// First, let's try sending a single task
	task0 := signatures.TaskSignature{
		Name: "add",
		Args: []signatures.TaskArg{
			signatures.TaskArg{
				Type:  "int64",
				Value: 1,
			},
			signatures.TaskArg{
				Type:  "int64",
				Value: 1,
			},
		},
	}

	asyncResult, err := server.SendTask(&task0)
	errors.Fail(err, "Could not send task")

	result, err := asyncResult.Get()
	errors.Fail(err, "Task failed with error")
	fmt.Printf("%v\n", result.Interface())

	// Now, let's try a chain of tasks
	task1 := signatures.TaskSignature{
		Name: "add",
		Args: []signatures.TaskArg{
			signatures.TaskArg{
				Type:  "int64",
				Value: 1,
			},
			signatures.TaskArg{
				Type:  "int64",
				Value: 1,
			},
		},
	}

	task2 := signatures.TaskSignature{
		Name: "add",
		Args: []signatures.TaskArg{
			signatures.TaskArg{
				Type:  "int64",
				Value: 5,
			},
			signatures.TaskArg{
				Type:  "int64",
				Value: 6,
			},
		},
	}

	task3 := signatures.TaskSignature{
		Name: "multiply",
		Args: []signatures.TaskArg{
			signatures.TaskArg{
				Type:  "int64",
				Value: 4,
			},
		},
	}

	chain := machinery.NewChain(&task1, &task2, &task3)
	chainAsyncResult, err := server.SendChain(chain)
	errors.Fail(err, "Could not send task")

	result, err = chainAsyncResult.Get()
	errors.Fail(err, "Chain failed with error")
	fmt.Printf("%v\n", result.Interface())
}