Skip to content

Commit

Permalink
Support FullyQualifiedMethodNames in CreateRetryableClient and log en…
Browse files Browse the repository at this point in the history
…hancements (#54)

* some logging improvements

* support for FullyQualifiedMethodNames in CreateRetryableClient
  • Loading branch information
simonporter authored Aug 5, 2016
1 parent 6481e6a commit de48fb1
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 8 deletions.
25 changes: 23 additions & 2 deletions Framework/OrchestrationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,33 @@ public virtual T CreateClient<T>(bool useFullyQualifiedMethodNames) where T : cl
/// <returns>Dynamic proxy that can be used to schedule the remote tasks</returns>
public virtual T CreateRetryableClient<T>(RetryOptions retryOptions) where T : class
{
if (!typeof (T).IsInterface)
return this.CreateRetryableClient<T>(retryOptions, false);
}

/// <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));
var scheduleProxy = new ScheduleProxy(this, typeof(T), useFullyQualifiedMethodNames);
var retryProxy = new RetryProxy<T>(this, retryOptions, scheduleProxy.ActLike<T>());
return retryProxy.ActLike<T>();
}
Expand Down
13 changes: 9 additions & 4 deletions Framework/ReflectionBasedTaskActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public override async Task<string> RunAsync(TaskContext context, string input)
if (methodParameters.Length < parameterCount)
{
throw new TaskFailureException(
"TaskActivity implementation cannot be invoked due to more than expected input parameters. Signature mismatch.");
this.FormatExceptionMessage("TaskActivity implementation cannot be invoked due to more than expected input parameters. Signature mismatch."));
}
var inputParameters = new object[methodParameters.Length];
for (int i = 0; i < methodParameters.Length; i++)
Expand Down Expand Up @@ -136,25 +136,30 @@ public override async Task<string> RunAsync(TaskContext context, string input)
{
Exception realException = e.InnerException ?? e;
string details = Utils.SerializeCause(realException, DataConverter);
throw new TaskFailureException(realException.Message, details);
throw new TaskFailureException(this.FormatExceptionMessage(realException.Message), details);
}
catch (Exception e) when (!Utils.IsFatal(e))
{
string details = Utils.SerializeCause(e, DataConverter);
throw new TaskFailureException(e.Message, e, details);
throw new TaskFailureException(this.FormatExceptionMessage(e.Message), e, details);
}

return serializedReturn;
}

/// <summary>
/// Invokes the target method on the actiivity object with supplied paarameters
/// Invokes the target method on the actiivity object with supplied parameters
/// </summary>
/// <param name="inputParameters"></param>
/// <returns></returns>
public virtual object InvokeActivity(object[] inputParameters)
{
return MethodInfo.Invoke(activityObject, inputParameters);
}

string FormatExceptionMessage(string message)
{
return $"{message}: @{this.MethodInfo.ReflectedType?.FullName}.{this.MethodInfo.Name}";
}
}
}
2 changes: 1 addition & 1 deletion Framework/TaskActivity.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ public override async Task<string> RunAsync(TaskContext context, string input)
catch (Exception e) when (!Utils.IsFatal(e))
{
string details = Utils.SerializeCause(e, DataConverter);
throw new TaskFailureException(e.Message, details);
throw new TaskFailureException(e.Message, e, details);
}

string serializedResult = DataConverter.Serialize(result);
Expand Down
3 changes: 2 additions & 1 deletion Framework/TaskOrchestrationDispatcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,8 @@ static TaskMessage ProcessWorkflowCompletedTaskDecision(

runtimeState.AddEvent(executionCompletedEvent);

TraceHelper.TraceInstance(TraceEventType.Information, runtimeState.OrchestrationInstance,
TraceHelper.TraceInstance(runtimeState.OrchestrationStatus == OrchestrationStatus.Failed ? TraceEventType.Warning : TraceEventType.Information,
runtimeState.OrchestrationInstance,
"Instance Id '{0}' completed in state {1} with result: {2}",
runtimeState.OrchestrationInstance, runtimeState.OrchestrationStatus, completeOrchestratorAction.Result);
TraceHelper.TraceInstance(TraceEventType.Information, runtimeState.OrchestrationInstance,
Expand Down

0 comments on commit de48fb1

Please sign in to comment.