Skip to content

Commit c2635a7

Browse files
authored
Merge branch 'main' into wangbill/versioning
2 parents d0cf4e7 + 2cde0ad commit c2635a7

9 files changed

Lines changed: 405 additions & 1 deletion

File tree

package-lock.json

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/durabletask-js/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ export { TOrchestrator } from "./types/orchestrator.type";
8181
export { TActivity } from "./types/activity.type";
8282
export { TInput } from "./types/input.type";
8383
export { TOutput } from "./types/output.type";
84+
export { ParentOrchestrationInstance } from "./types/parent-orchestration-instance.type";
8485

8586
// Logger
8687
export { Logger, ConsoleLogger, NoOpLogger } from "./types/logger.type";

packages/durabletask-js/src/task/context/orchestration-context.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT License.
33

4+
import { ParentOrchestrationInstance } from "../../types/parent-orchestration-instance.type";
45
import { TActivity } from "../../types/activity.type";
56
import { TOrchestrator } from "../../types/orchestrator.type";
67
import { Logger } from "../../types/logger.type";
@@ -20,6 +21,16 @@ export abstract class OrchestrationContext {
2021
*/
2122
abstract get instanceId(): string;
2223

24+
/**
25+
* Gets the parent orchestration instance, or `undefined` if this is not a sub-orchestration.
26+
*
27+
* This property is useful for determining if the current orchestration was started by another
28+
* orchestration (i.e., it's a sub-orchestration) and for accessing details about the parent.
29+
*
30+
* @returns {ParentOrchestrationInstance | undefined} The parent orchestration details, or `undefined` if this is a top-level orchestration.
31+
*/
32+
abstract get parent(): ParentOrchestrationInstance | undefined;
33+
2334
/**
2435
* Get the current date/time as UTC
2536
*
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
/**
5+
* Represents the parent orchestration instance details for a sub-orchestration.
6+
*
7+
* This information is available when an orchestration is started as a sub-orchestration
8+
* by another orchestration. It provides details about the parent that started this
9+
* orchestration, which can be useful for debugging and tracing.
10+
*/
11+
export interface ParentOrchestrationInstance {
12+
/**
13+
* The name of the parent orchestration.
14+
*/
15+
name: string;
16+
17+
/**
18+
* The unique instance ID of the parent orchestration.
19+
*/
20+
instanceId: string;
21+
22+
/**
23+
* The task scheduled ID that corresponds to this sub-orchestration in the parent's history.
24+
*/
25+
taskScheduledId: number;
26+
}

packages/durabletask-js/src/utils/pb-helper.util.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export function newOrchestratorStartedEvent(timestamp?: Date | null): pb.History
2222
return event;
2323
}
2424

25-
export function newExecutionStartedEvent(name: string, instanceId: string, encodedInput?: string): pb.HistoryEvent {
25+
export function newExecutionStartedEvent(name: string, instanceId: string, encodedInput?: string, parentInstance?: { name: string; instanceId: string; taskScheduledId: number }): pb.HistoryEvent {
2626
const ts = new Timestamp();
2727

2828
const orchestrationInstance = new pb.OrchestrationInstance();
@@ -33,6 +33,19 @@ export function newExecutionStartedEvent(name: string, instanceId: string, encod
3333
executionStartedEvent.setInput(getStringValue(encodedInput));
3434
executionStartedEvent.setOrchestrationinstance(orchestrationInstance);
3535

36+
// Set parent instance info if provided (for sub-orchestrations)
37+
if (parentInstance) {
38+
const parentOrchestrationInstance = new pb.OrchestrationInstance();
39+
parentOrchestrationInstance.setInstanceid(parentInstance.instanceId);
40+
41+
const parentInstanceInfo = new pb.ParentInstanceInfo();
42+
parentInstanceInfo.setName(getStringValue(parentInstance.name));
43+
parentInstanceInfo.setOrchestrationinstance(parentOrchestrationInstance);
44+
parentInstanceInfo.setTaskscheduledid(parentInstance.taskScheduledId);
45+
46+
executionStartedEvent.setParentinstance(parentInstanceInfo);
47+
}
48+
3649
const event = new pb.HistoryEvent();
3750
event.setEventid(-1);
3851
event.setTimestamp(ts);

packages/durabletask-js/src/worker/orchestration-executor.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,17 @@ export class OrchestrationExecutor {
132132
// Set the version from the execution started event
133133
ctx._version = executionStartedEvent?.getVersion()?.getValue() ?? "";
134134

135+
// Extract parent instance info if this is a sub-orchestration
136+
const parentInstance = executionStartedEvent?.getParentinstance();
137+
if (parentInstance) {
138+
const parentOrchestrationInstance = parentInstance.getOrchestrationinstance();
139+
ctx._parent = {
140+
name: parentInstance.getName()?.getValue() ?? "",
141+
instanceId: parentOrchestrationInstance?.getInstanceid() ?? "",
142+
taskScheduledId: parentInstance.getTaskscheduledid(),
143+
};
144+
}
145+
135146
// Deserialize the input, if any
136147
let input = undefined;
137148

packages/durabletask-js/src/worker/runtime-orchestration-context.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import { createHash } from "crypto";
55
import { getName } from "../task";
66
import { OrchestrationContext } from "../task/context/orchestration-context";
7+
import { ParentOrchestrationInstance } from "../types/parent-orchestration-instance.type";
78
import * as pb from "../proto/orchestrator_service_pb";
89
import * as ph from "../utils/pb-helper.util";
910
import { CompletableTask } from "../task/completable-task";
@@ -29,6 +30,7 @@ export class RuntimeOrchestrationContext extends OrchestrationContext {
2930
_currentUtcDatetime: Date;
3031
_instanceId: string;
3132
_version: string;
33+
_parent?: ParentOrchestrationInstance;
3234
_completionStatus?: pb.OrchestrationStatus;
3335
_receivedEvents: Record<string, any[]>;
3436
_pendingEvents: Record<string, CompletableTask<any>[]>;
@@ -50,6 +52,7 @@ export class RuntimeOrchestrationContext extends OrchestrationContext {
5052
this._currentUtcDatetime = new Date(1000, 0, 1);
5153
this._instanceId = instanceId;
5254
this._version = "";
55+
this._parent = undefined;
5356
this._completionStatus = undefined;
5457
this._receivedEvents = {};
5558
this._pendingEvents = {};
@@ -62,6 +65,10 @@ export class RuntimeOrchestrationContext extends OrchestrationContext {
6265
return this._instanceId;
6366
}
6467

68+
get parent(): ParentOrchestrationInstance | undefined {
69+
return this._parent;
70+
}
71+
6572
get currentUtcDateTime(): Date {
6673
return this._currentUtcDatetime;
6774
}

0 commit comments

Comments
 (0)