Example #1
0
// Get returns task result (synchronous blocking call)
func (asyncResult *AsyncResult) Get() (reflect.Value, error) {
	if asyncResult.backend == nil {
		return reflect.Value{}, errors.New("Result backend not configured")
	}

	for {
		asyncResult.GetState()

		if asyncResult.taskState.IsSuccess() {
			// Purge state if we are using AMQP backend
			_, ok := asyncResult.backend.(*AMQPBackend)
			if ok && asyncResult.taskState.IsCompleted() {
				asyncResult.backend.PurgeState(asyncResult.signature)
			}

			return utils.ReflectValue(
				asyncResult.taskState.Result.Type,
				asyncResult.taskState.Result.Value,
			)
		}

		if asyncResult.taskState.IsFailure() {
			// Purge state if we are using AMQP backend
			_, ok := asyncResult.backend.(*AMQPBackend)
			if ok && asyncResult.taskState.IsCompleted() {
				asyncResult.backend.PurgeState(asyncResult.signature)
			}

			return reflect.Value{}, errors.New(asyncResult.taskState.Error)
		}
	}
}
Example #2
0
// Converts []TaskArg to []reflect.Value
func (worker *Worker) reflectArgs(args []signatures.TaskArg) ([]reflect.Value, error) {
	argValues := make([]reflect.Value, len(args))

	for i, arg := range args {
		argValue, err := utils.ReflectValue(arg.Type, arg.Value)
		if err != nil {
			return nil, err
		}
		argValues[i] = argValue
	}

	return argValues, nil
}