Ejemplo n.º 1
0
        /// <summary>
        ///     Creates a proxy client with built-in retry logic.
        /// </summary>
        /// <typeparam name="T">
        ///     Task version of the client interface.
        ///     This is similar to the actual interface implemented by the client but with the
        ///     return types always of the form Task&lt;TOriginal&gt;
        ///     where TOriginal was the return
        ///     type for the same method in the original interface
        /// </typeparam>
        /// <param name="retryOptions">Retry policies</param>
        /// <param name="useFullyQualifiedMethodNames">
        ///     If true, the method name translation from the interface contains
        ///     the interface name, if false then only the method name is used
        /// </param>
        /// <returns>Dynamic proxy that can be used to schedule the remote tasks</returns>
        public virtual T CreateRetryableClient <T>(RetryOptions retryOptions, bool useFullyQualifiedMethodNames) where T : class
        {
            if (!typeof(T).IsInterface)
            {
                throw new InvalidOperationException("Pass in an interface.");
            }

            var scheduleProxy = new ScheduleProxy(this, typeof(T), useFullyQualifiedMethodNames);
            var retryProxy    = new RetryProxy <T>(this, retryOptions, scheduleProxy.ActLike <T>());

            return(retryProxy.ActLike <T>());
        }
Ejemplo n.º 2
0
        /// <summary>
        ///     Creates a proxy client with built-in retry logic.
        /// </summary>
        /// <typeparam name="T">
        ///     Task version of the client interface.
        ///     This is similar to the actual interface implemented by the client but with the
        ///     return types always of the form Task&lt;TOriginal&gt;
        ///     where TOriginal was the return
        ///     type for the same method in the original interface
        /// </typeparam>
        /// <param name="retryOptions">Retry policies</param>
        /// <param name="useFullyQualifiedMethodNames">
        ///     If true, the method name translation from the interface contains
        ///     the interface name, if false then only the method name is used
        /// </param>
        /// <returns>Dynamic proxy that can be used to schedule the remote tasks</returns>
        public virtual T CreateRetryableClient <T>(RetryOptions retryOptions, bool useFullyQualifiedMethodNames) where T : class
        {
            if (!typeof(T).IsInterface)
            {
                throw new InvalidOperationException("Pass in an interface.");
            }

            IInterceptor scheduleProxy = new ScheduleProxy(this, useFullyQualifiedMethodNames);
            IInterceptor retryProxy    = new RetryProxy(this, retryOptions);

            T scheduleInstance = ProxyGenerator.CreateInterfaceProxyWithoutTarget <T>(scheduleProxy);

            return(ProxyGenerator.CreateInterfaceProxyWithTarget(scheduleInstance, retryProxy));
        }
Ejemplo n.º 3
0
        public RetryProxy(OrchestrationContext context, RetryOptions retryOptions, T wrappedObject)
        {
            this.context       = context;
            this.retryOptions  = retryOptions;
            this.wrappedObject = wrappedObject;

            //If type can be determined by name
            returnTypes = typeof(T).GetMethods()
                          .Where(method => !method.IsSpecialName)
                          .GroupBy(method => method.Name)
                          .Where(group => group.Select(method => method.ReturnType).Distinct().Count() == 1)
                          .Select(group => new
            {
                Name       = group.Key,
                ReturnType = group.Select(method => method.ReturnType).Distinct().Single()
            })
                          .ToDictionary(info => info.Name, info => info.ReturnType);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Creates a new instance of the RetryInterceptor with specified parameters
 /// </summary>
 /// <param name="context">The orchestration context of the function call</param>
 /// <param name="retryOptions">The options for performing retries</param>
 /// <param name="retryCall">The code to execute</param>
 public RetryInterceptor(OrchestrationContext context, RetryOptions retryOptions, Func <Task <T> > retryCall)
 {
     this.context      = context;
     this.retryOptions = retryOptions;
     this.retryCall    = retryCall;
 }
Ejemplo n.º 5
0
 /// <summary>
 /// Creates a new instance RetryOptions with the supplied first retry and max attempts
 /// </summary>
 /// <param name="firstRetryInterval">Timespan to wait for the first retry</param>
 /// <param name="maxNumberOfAttempts">Max number of attempts to retry</param>
 /// <exception cref="ArgumentException">
 /// The TimeSpan value must be greater than TimeSpan.Zero.
 /// </exception>
 public RetryOptions(TimeSpan firstRetryInterval, int maxNumberOfAttempts)
 {
     retryOptions = new DurableTaskCore.RetryOptions(firstRetryInterval, maxNumberOfAttempts);
 }
Ejemplo n.º 6
0
 /// <summary>
 ///     Creates a proxy client with built-in retry logic.
 /// </summary>
 /// <typeparam name="T">
 ///     Task version of the client interface.
 ///     This is similar to the actual interface implemented by the client but with the
 ///     return types always of the form Task&lt;TOriginal&gt;
 ///     where TOriginal was the return
 ///     type for the same method in the original interface
 /// </typeparam>
 /// <param name="retryOptions">Retry policies</param>
 /// <returns>Dynamic proxy that can be used to schedule the remote tasks</returns>
 public virtual T CreateRetryableClient <T>(RetryOptions retryOptions) where T : class
 {
     return(this.CreateRetryableClient <T>(retryOptions, false));
 }
Ejemplo n.º 7
0
 /// <summary>
 ///     Create a sub-orchestration of the specified type. Also retry on failure as per supplied policy.
 /// </summary>
 /// <typeparam name="T">Return Type of the TaskOrchestration.RunTask method</typeparam>
 /// <param name="orchestrationType">Type of the TaskOrchestration derived class to instantiate</param>
 /// <param name="instanceId">Instance Id of the sub-orchestration</param>
 /// <param name="retryOptions">Retry policy</param>
 /// <param name="input">Input for the TaskOrchestration.RunTask method</param>
 /// <returns>Task that represents the execution of the specified sub-orchestration</returns>
 public virtual Task <T> CreateSubOrchestrationInstanceWithRetry <T>(Type orchestrationType, string instanceId,
                                                                     RetryOptions retryOptions, object input)
 {
     return(CreateSubOrchestrationInstanceWithRetry <T>(NameVersionHelper.GetDefaultName(orchestrationType),
                                                        NameVersionHelper.GetDefaultVersion(orchestrationType), instanceId, retryOptions, input));
 }
Ejemplo n.º 8
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RetryProxy"/> class.
 /// </summary>
 /// <param name="context">The orchestration context.</param>
 /// <param name="retryOptions">The retry options.</param>
 public RetryProxy(OrchestrationContext context, RetryOptions retryOptions)
 {
     this.context      = context;
     this.retryOptions = retryOptions;
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Creates a new instance RetryOptions with the supplied first retry and max attempts.
 /// </summary>
 /// <param name="firstRetryInterval">Timespan to wait for the first retry.</param>
 /// <param name="maxNumberOfAttempts">Max number of attempts to retry.</param>
 /// <exception cref="ArgumentException">
 /// The <paramref name="firstRetryInterval"/> value must be greater than <see cref="TimeSpan.Zero"/>.
 /// </exception>
 public RetryOptions(TimeSpan firstRetryInterval, int maxNumberOfAttempts)
 {
     this.retryOptions     = new DurableTaskCore.RetryOptions(firstRetryInterval, maxNumberOfAttempts);
     this.MaxRetryInterval = DefaultMaxRetryinterval;
 }