Repository navigation
💥 Standalone activity support #609
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 3 commits
a8e66be
d0384a0
86b8621
287ed97
4d16ca3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,6 +19,7 @@ namespace Temporalio.Activities | |
| /// <param name="HeartbeatDetails">Details from the last heartbeat of the last attempt.</param> | ||
| /// <param name="HeartbeatTimeout">Heartbeat timeout set by the caller.</param> | ||
| /// <param name="IsLocal">Whether the activity is a local activity or not.</param> | ||
| /// <param name="Namespace">Namespace this activity is on.</param> | ||
| /// <param name="Priority">The Priority of this activity.</param> | ||
| /// <param name="RetryPolicy"> | ||
| /// The retry policy of this activity. | ||
|
|
@@ -34,10 +35,14 @@ namespace Temporalio.Activities | |
| /// <param name="StartedTime">When the activity started.</param> | ||
| /// <param name="TaskQueue">Task queue this activity is on.</param> | ||
| /// <param name="TaskToken">Task token uniquely identifying this activity.</param> | ||
| /// <param name="WorkflowId">Workflow ID that started this activity.</param> | ||
| /// <param name="WorkflowNamespace">Namespace this activity is on.</param> | ||
| /// <param name="WorkflowRunId">Workflow run ID that started this activity.</param> | ||
| /// <param name="WorkflowType">Workflow type name that started this activity.</param> | ||
| /// <param name="WorkflowId">Workflow ID that started this activity, or null for standalone | ||
| /// activities.</param> | ||
| /// <param name="WorkflowNamespace">Namespace of the workflow that started this activity, or | ||
| /// null for standalone activities.</param> | ||
| /// <param name="WorkflowRunId">Workflow run ID that started this activity, or null for | ||
| /// standalone activities.</param> | ||
| /// <param name="WorkflowType">Workflow type name that started this activity, or null for | ||
| /// standalone activities.</param> | ||
| /// <remarks> | ||
| /// WARNING: This constructor may have required properties added. Do not rely on the exact | ||
| /// constructor, only use "with" clauses. | ||
|
|
@@ -51,6 +56,7 @@ public record ActivityInfo( | |
| IReadOnlyCollection<Payload> HeartbeatDetails, | ||
| TimeSpan? HeartbeatTimeout, | ||
| bool IsLocal, | ||
| string Namespace, | ||
| Temporalio.Common.Priority Priority, | ||
| Temporalio.Common.RetryPolicy? RetryPolicy, | ||
| TimeSpan? ScheduleToCloseTimeout, | ||
|
|
@@ -59,11 +65,17 @@ public record ActivityInfo( | |
| DateTime StartedTime, | ||
| string TaskQueue, | ||
| byte[] TaskToken, | ||
| string WorkflowId, | ||
| string WorkflowNamespace, | ||
| string WorkflowRunId, | ||
| string WorkflowType) | ||
| string? WorkflowId, | ||
| string? WorkflowNamespace, | ||
| string? WorkflowRunId, | ||
| string? WorkflowType) | ||
| { | ||
| /// <summary> | ||
| /// Gets a value indicating whether this activity was started by a workflow. | ||
| /// </summary> | ||
| /// <remarks>WARNING: Standalone activities are experimental.</remarks> | ||
| public bool IsWorkflowActivity => WorkflowId != null; | ||
|
|
||
| /// <summary> | ||
| /// Gets the value that is set on | ||
| /// <see cref="Microsoft.Extensions.Logging.ILogger.BeginScope" /> before this activity is | ||
|
|
@@ -74,10 +86,10 @@ public record ActivityInfo( | |
| ["ActivityId"] = ActivityId, | ||
| ["ActivityType"] = ActivityType, | ||
| ["Attempt"] = Attempt, | ||
| ["WorkflowNamespace"] = WorkflowNamespace, | ||
| ["WorkflowId"] = WorkflowId, | ||
| ["WorkflowRunId"] = WorkflowRunId, | ||
| ["WorkflowType"] = WorkflowType, | ||
| ["Namespace"] = Namespace, | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we maybe preserve WorkflowNamespace and only fill it if it's workflow activity? That way we don't wholesale break anyone who is scraping logs, especially for those who aren't using this experimental feature yet.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We can, though the question is whether we should also emit a
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thinking this through... Previously, With my suggestion, So questions are:
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Right, all of that makes sense, and I don't have a strong opinion on whether to break existing log scope keys now, later, or not at all. It makes sense for me to put What I was asking was a followup question - do we emit
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we always emit
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 I will add the redundant log tag for the majority of users
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Meaning all workflow logs will have
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm fine with theremoval of
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Same for other workflow tags. Can you take a look at 287ed97 and confirm it is what you were thinking?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. lgtm |
||
| ["WorkflowId"] = WorkflowId ?? string.Empty, | ||
| ["WorkflowRunId"] = WorkflowRunId ?? string.Empty, | ||
| ["WorkflowType"] = WorkflowType ?? string.Empty, | ||
| }; | ||
|
|
||
| /// <summary> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| using System; | ||
|
|
||
| namespace Temporalio.Client | ||
| { | ||
| /// <summary> | ||
| /// Options for canceling a standalone activity. | ||
| /// </summary> | ||
| /// <remarks>WARNING: Standalone activities are experimental.</remarks> | ||
| public class ActivityCancelOptions : ICloneable | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the reason for the cancellation request. | ||
| /// </summary> | ||
| public string? Reason { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets RPC options for canceling the activity. | ||
| /// </summary> | ||
| public RpcOptions? Rpc { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Create a shallow copy of these options. | ||
| /// </summary> | ||
| /// <returns>A shallow copy of these options and any transitive options fields.</returns> | ||
| public virtual object Clone() | ||
| { | ||
| var copy = (ActivityCancelOptions)MemberwiseClone(); | ||
| if (Rpc != null) | ||
| { | ||
| copy.Rpc = (RpcOptions)Rpc.Clone(); | ||
| } | ||
| return copy; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| using System; | ||
|
|
||
| namespace Temporalio.Client | ||
| { | ||
| /// <summary> | ||
| /// Options for <see cref="ITemporalClient.CountActivitiesAsync" />. | ||
| /// </summary> | ||
| /// <remarks>WARNING: Standalone activities are experimental.</remarks> | ||
| public class ActivityCountOptions : ICloneable | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets RPC options for counting activities. | ||
| /// </summary> | ||
| public RpcOptions? Rpc { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Create a shallow copy of these options. | ||
| /// </summary> | ||
| /// <returns>A shallow copy of these options and any transitive options fields.</returns> | ||
| public virtual object Clone() | ||
| { | ||
| var copy = (ActivityCountOptions)MemberwiseClone(); | ||
| if (Rpc != null) | ||
| { | ||
| copy.Rpc = (RpcOptions)Rpc.Clone(); | ||
| } | ||
| return copy; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| using System; | ||
|
|
||
| namespace Temporalio.Client | ||
| { | ||
| /// <summary> | ||
| /// Options for describing a standalone activity. | ||
| /// </summary> | ||
| /// <remarks>WARNING: Standalone activities are experimental.</remarks> | ||
| public class ActivityDescribeOptions : ICloneable | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets a long-poll token from a previous describe response. When set, the | ||
| /// describe call will long-poll for state changes. | ||
| /// </summary> | ||
| public byte[]? LongPollToken { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets RPC options for describing the activity. | ||
| /// </summary> | ||
| public RpcOptions? Rpc { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Create a shallow copy of these options. | ||
| /// </summary> | ||
| /// <returns>A shallow copy of these options and any transitive options fields.</returns> | ||
| public virtual object Clone() | ||
| { | ||
| var copy = (ActivityDescribeOptions)MemberwiseClone(); | ||
| if (Rpc != null) | ||
| { | ||
| copy.Rpc = (RpcOptions)Rpc.Clone(); | ||
| } | ||
| return copy; | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,144 @@ | ||
| using System; | ||
| using System.Threading; | ||
| using Temporalio.Api.Activity.V1; | ||
| using Temporalio.Api.Enums.V1; | ||
| using Temporalio.Common; | ||
|
|
||
| namespace Temporalio.Client | ||
| { | ||
| /// <summary> | ||
| /// Representation of a standalone activity execution from a list call. | ||
| /// </summary> | ||
| /// <remarks>WARNING: Standalone activities are experimental.</remarks> | ||
| public class ActivityExecution | ||
| { | ||
| private readonly Lazy<SearchAttributeCollection> searchAttributes; | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ActivityExecution"/> class from list info. | ||
| /// </summary> | ||
| /// <param name="rawInfo">Raw proto list info.</param> | ||
| /// <param name="clientNamespace">Client namespace.</param> | ||
| /// <remarks>WARNING: This constructor may be mutated in backwards incompatible ways.</remarks> | ||
| protected internal ActivityExecution( | ||
| ActivityExecutionListInfo rawInfo, string clientNamespace) | ||
| : this( | ||
| clientNamespace: clientNamespace, | ||
| activityId: rawInfo.ActivityId, | ||
| activityRunId: string.IsNullOrEmpty(rawInfo.RunId) ? null : rawInfo.RunId, | ||
| activityType: rawInfo.ActivityType?.Name ?? string.Empty, | ||
|
jmaeagle99 marked this conversation as resolved.
Resolved
|
||
| closeTime: rawInfo.CloseTime?.ToDateTime(), | ||
| executionDuration: rawInfo.ExecutionDuration?.ToTimeSpan(), | ||
| scheduledTime: rawInfo.ScheduleTime?.ToDateTime() ?? default, | ||
|
jmaeagle99 marked this conversation as resolved.
Resolved
|
||
| stateTransitionCount: rawInfo.StateTransitionCount, | ||
| status: rawInfo.Status, | ||
| taskQueue: rawInfo.TaskQueue, | ||
| searchAttributesFactory: () => rawInfo.SearchAttributes == null ? | ||
| SearchAttributeCollection.Empty : | ||
| SearchAttributeCollection.FromProto(rawInfo.SearchAttributes)) | ||
| { | ||
| RawInfo = rawInfo; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ActivityExecution"/> class. | ||
| /// </summary> | ||
| /// <param name="clientNamespace">Client namespace.</param> | ||
| /// <param name="activityId">Activity ID.</param> | ||
| /// <param name="activityRunId">Activity run ID.</param> | ||
| /// <param name="activityType">Activity type name.</param> | ||
| /// <param name="closeTime">Close time.</param> | ||
| /// <param name="executionDuration">Execution duration.</param> | ||
| /// <param name="scheduledTime">Scheduled time.</param> | ||
| /// <param name="stateTransitionCount">State transition count.</param> | ||
| /// <param name="status">Activity status.</param> | ||
| /// <param name="taskQueue">Task queue.</param> | ||
| /// <param name="searchAttributesFactory">Factory for lazy search attribute creation.</param> | ||
| private protected ActivityExecution( | ||
| string clientNamespace, | ||
| string activityId, | ||
| string? activityRunId, | ||
| string activityType, | ||
| DateTime? closeTime, | ||
| TimeSpan? executionDuration, | ||
| DateTime scheduledTime, | ||
| long stateTransitionCount, | ||
| ActivityExecutionStatus status, | ||
| string taskQueue, | ||
| Func<SearchAttributeCollection> searchAttributesFactory) | ||
| { | ||
| Namespace = clientNamespace; | ||
| ActivityId = activityId; | ||
| ActivityRunId = activityRunId; | ||
| ActivityType = activityType; | ||
| CloseTime = closeTime; | ||
| ExecutionDuration = executionDuration; | ||
| ScheduledTime = scheduledTime; | ||
| StateTransitionCount = stateTransitionCount; | ||
| Status = status; | ||
| TaskQueue = taskQueue; | ||
| searchAttributes = new(searchAttributesFactory, LazyThreadSafetyMode.PublicationOnly); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Gets the activity ID. | ||
| /// </summary> | ||
| public string ActivityId { get; private init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the activity run ID. | ||
| /// </summary> | ||
| public string? ActivityRunId { get; private init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the activity type name. | ||
| /// </summary> | ||
| public string ActivityType { get; private init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets when the activity was closed if in a terminal state. | ||
| /// </summary> | ||
| public DateTime? CloseTime { get; private init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the total execution duration if the activity is closed. | ||
| /// </summary> | ||
| public TimeSpan? ExecutionDuration { get; private init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the namespace. | ||
| /// </summary> | ||
| public string Namespace { get; private init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets when the activity was originally scheduled. | ||
| /// </summary> | ||
| public DateTime ScheduledTime { get; private init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the number of state transitions. | ||
| /// </summary> | ||
| public long StateTransitionCount { get; private init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the status of the activity. | ||
| /// </summary> | ||
| public ActivityExecutionStatus Status { get; private init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the task queue for the activity. | ||
| /// </summary> | ||
| public string TaskQueue { get; private init; } | ||
|
|
||
| /// <summary> | ||
| /// Gets the search attributes on the activity. | ||
| /// </summary> | ||
| /// <remarks>This is lazily converted on first access.</remarks> | ||
| public SearchAttributeCollection TypedSearchAttributes => searchAttributes.Value; | ||
|
|
||
| /// <summary> | ||
| /// Gets the raw proto list info, or null if this was created from a describe call. | ||
| /// </summary> | ||
| internal ActivityExecutionListInfo? RawInfo { get; private init; } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note, we will need to merge this branch into
featuresrepo right after this PR is merged.