Skip to content

Commit 9e75c40

Browse files
authored
Second bunch of enhancements and fixes (#873)
1 parent d545898 commit 9e75c40

File tree

18 files changed

+197
-78
lines changed

18 files changed

+197
-78
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ jobs:
4545
with:
4646
repository: temporalio/docker-compose
4747
path: docker-compose
48+
ref: v1.17.5 # TODO: Upgrade to 1.18 - has a bug where search attributes are not deleted
4849
if: ${{ startsWith(matrix.os, 'ubuntu') }}
4950

5051
- name: Start Temporal Server

package-lock.json

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

packages/client/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,12 @@
1818
"@temporalio/internal-non-workflow-common": "file:../internal-non-workflow-common",
1919
"@temporalio/internal-workflow-common": "file:../internal-workflow-common",
2020
"@temporalio/proto": "file:../proto",
21-
"long": "^5.2.0",
2221
"ms": "^2.1.3",
23-
"protobufjs": "^7.0.0",
2422
"uuid": "^8.3.2"
2523
},
24+
"devDependencies": {
25+
"protobufjs": "^7.0.0"
26+
},
2627
"bugs": {
2728
"url": "https://github.com/temporalio/sdk-typescript/issues"
2829
},

packages/client/src/async-completion-client.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,8 @@ export class AsyncCompletionClient {
119119
/**
120120
* Raw gRPC access to the Temporal service.
121121
*
122-
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made to the service.
122+
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made via this service
123+
* object.
123124
*/
124125
get workflowService(): WorkflowService {
125126
return this.connection.workflowService;

packages/client/src/client.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ export function defaultClientOptions(): ClientOptionsWithDefaults {
8080

8181
/**
8282
* High level SDK client.
83-
*
84-
*
8583
*/
8684
export class Client {
8785
/**
@@ -126,7 +124,8 @@ export class Client {
126124
/**
127125
* Raw gRPC access to the Temporal service.
128126
*
129-
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made to the service.
127+
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made via this service
128+
* object.
130129
*/
131130
get workflowService(): WorkflowService {
132131
return this.connection.workflowService;

packages/client/src/types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import type { SearchAttributes } from '@temporalio/internal-workflow-common';
22
import * as proto from '@temporalio/proto';
33
import type * as grpc from '@grpc/grpc-js';
4-
import Long from 'long';
54

65
export interface WorkflowExecution {
76
workflowId: string;
@@ -34,7 +33,7 @@ export interface WorkflowExecutionDescription {
3433
runId: string;
3534
taskQueue: string;
3635
status: { code: proto.temporal.api.enums.v1.WorkflowExecutionStatus; name: WorkflowExecutionStatusName };
37-
historyLength: Long;
36+
historyLength: number;
3837
startTime: Date;
3938
executionTime?: Date;
4039
closeTime?: Date;

packages/client/src/workflow-client.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ export class WorkflowClient {
310310
/**
311311
* Raw gRPC access to the Temporal service.
312312
*
313-
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made to the service.
313+
* **NOTE**: The namespace provided in {@link options} is **not** automatically set on requests made via this service
314+
* object.
314315
*/
315316
get workflowService(): WorkflowService {
316317
return this.connection.workflowService;
@@ -860,10 +861,8 @@ export class WorkflowClient {
860861
code: raw.workflowExecutionInfo!.status!,
861862
name: workflowStatusCodeToName(raw.workflowExecutionInfo!.status!),
862863
},
863-
// Technically safe to convert to number, unfortunately this was overlooked when this was originally
864-
// implemented.
865-
// Max history length is 50k, which is much less than Number.MAX_SAFE_INTEGER
866-
historyLength: raw.workflowExecutionInfo!.historyLength!,
864+
// Safe to convert to number, max history length is 50k, which is much less than Number.MAX_SAFE_INTEGER
865+
historyLength: raw.workflowExecutionInfo!.historyLength!.toNumber(),
867866
startTime: tsToDate(raw.workflowExecutionInfo!.startTime!),
868867
executionTime: optionalTsToDate(raw.workflowExecutionInfo!.executionTime),
869868
closeTime: optionalTsToDate(raw.workflowExecutionInfo!.closeTime),

packages/core-bridge/Cargo.lock

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

packages/core-bridge/src/worker.rs

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -123,12 +123,11 @@ pub async fn start_worker_loop(
123123
.with_context(otel_ctx)
124124
.await
125125
},
126-
|cx, err| match err {
127-
CompleteWfError::TonicError(_) => {
128-
TRANSPORT_ERROR.from_error(cx, err)
129-
}
130-
CompleteWfError::MalformedWorkflowCompletion { reason, .. } => {
131-
Ok(JsError::type_error(cx, reason)?.upcast())
126+
|cx, err| -> JsResult<JsObject> {
127+
match err {
128+
CompleteWfError::MalformedWorkflowCompletion {
129+
reason, ..
130+
} => Ok(JsError::type_error(cx, reason)?.upcast()),
132131
}
133132
},
134133
)
@@ -150,13 +149,12 @@ pub async fn start_worker_loop(
150149
.with_context(otel_ctx)
151150
.await
152151
},
153-
|cx, err| match err {
154-
CompleteActivityError::MalformedActivityCompletion {
155-
reason,
156-
..
157-
} => Ok(JsError::type_error(cx, reason)?.upcast()),
158-
CompleteActivityError::TonicError(_) => {
159-
TRANSPORT_ERROR.from_error(cx, err)
152+
|cx, err| -> JsResult<JsObject> {
153+
match err {
154+
CompleteActivityError::MalformedActivityCompletion {
155+
reason,
156+
..
157+
} => Ok(JsError::type_error(cx, reason)?.upcast()),
160158
}
161159
},
162160
)
@@ -199,10 +197,7 @@ async fn handle_poll_workflow_activation_request(
199197
Err(err) => {
200198
send_error(channel, callback, move |cx| match err {
201199
PollWfError::ShutDown => SHUTDOWN_ERROR.from_error(cx, err),
202-
PollWfError::TonicError(_)
203-
| PollWfError::AutocompleteError(CompleteWfError::TonicError(_)) => {
204-
TRANSPORT_ERROR.from_error(cx, err)
205-
}
200+
PollWfError::TonicError(_) => TRANSPORT_ERROR.from_error(cx, err),
206201
PollWfError::AutocompleteError(CompleteWfError::MalformedWorkflowCompletion {
207202
reason,
208203
..

packages/internal-workflow-common/src/activity-options.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,18 @@ Note that the Temporal Server doesn't detect Worker process failures directly. I
7979
* - `ABANDON` - Do not request cancellation of the activity and immediately report cancellation to the workflow.
8080
*/
8181
cancellationType?: ActivityCancellationType;
82+
83+
/**
84+
* Eager dispatch is an optimization that improves the throughput and load on the server for scheduling Activities.
85+
* When used, the server will hand out Activity tasks back to the Worker when it completes a Workflow task.
86+
* It is available from server version 1.17 behind the `system.enableActivityEagerExecution` feature flag.
87+
*
88+
* Eager dispatch will only be used if `allowEagerDispatch` is enabled (the default) and {@link taskQueue} is either
89+
* omitted or the same as the current Workflow.
90+
*
91+
* @default true
92+
*/
93+
allowEagerDispatch?: boolean;
8294
}
8395

8496
/**

packages/test/src/test-ephemeral-server.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,12 @@ async function runSimpleWorkflow(t: ExecutionContext<Context>, testEnv: TestWork
3636
}
3737

3838
test('TestEnvironment sets up test server and is able to run a single workflow', async (t) => {
39-
const testEnv = await TestWorkflowEnvironment.create();
39+
const testEnv = await TestWorkflowEnvironment.createTimeSkipping();
4040
await runSimpleWorkflow(t, testEnv);
4141
});
4242

4343
test('TestEnvironment sets up temporalite and is able to run a single workflow', async (t) => {
44-
const testEnv = await TestWorkflowEnvironment.create({ type: 'temporalite' });
44+
const testEnv = await TestWorkflowEnvironment.createLocal();
4545
await runSimpleWorkflow(t, testEnv);
4646
});
4747

packages/test/src/test-testenvironment.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { WorkflowFailedError } from '@temporalio/client';
22
import { TestWorkflowEnvironment, workflowInterceptorModules } from '@temporalio/testing';
3+
import { Connection } from '@temporalio/testing/lib/connection';
34
import { Runtime, Worker } from '@temporalio/worker';
45
import anyTest, { TestInterface } from 'ava';
56
import { v4 as uuid4 } from 'uuid';
@@ -22,7 +23,7 @@ test.before(async (t) => {
2223
telemetryOptions: { tracingFilter: 'DEBUG' },
2324
});
2425
t.context = {
25-
testEnv: await TestWorkflowEnvironment.create({}),
26+
testEnv: await TestWorkflowEnvironment.createTimeSkipping(),
2627
};
2728
});
2829

@@ -120,7 +121,7 @@ test.serial('TestEnvironment sleep can be used to delay sending a signal', async
120121
const { client, nativeConnection, sleep } = t.context.testEnv;
121122
// TODO: due to the test server issue mentioned in the test avove we need to manually unlock time skipping
122123
// for the current test to balance out the time skipping lock counter.
123-
await t.context.testEnv.connection.testService.unlockTimeSkipping({});
124+
await (t.context.testEnv.connection as Connection).testService.unlockTimeSkipping({});
124125

125126
const worker = await Worker.create({
126127
connection: nativeConnection,

packages/test/src/test-workflow-log-interceptor.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ const test = anyTest as TestInterface<Context>;
1111

1212
test.before(async (t) => {
1313
t.context = {
14-
testEnv: await TestWorkflowEnvironment.create(),
14+
testEnv: await TestWorkflowEnvironment.createTimeSkipping(),
1515
};
1616
});
1717

packages/test/src/test-workflows.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,7 @@ test('cancelWorkflow', async (t) => {
743743
arguments: toPayloads(defaultPayloadConverter, url),
744744
startToCloseTimeout: msToTs('10m'),
745745
taskQueue: 'test',
746+
doNotEagerlyExecute: false,
746747
}),
747748
])
748749
);
@@ -776,6 +777,7 @@ test('cancelWorkflow', async (t) => {
776777
arguments: toPayloads(defaultPayloadConverter, url),
777778
startToCloseTimeout: msToTs('10m'),
778779
taskQueue: 'test',
780+
doNotEagerlyExecute: false,
779781
}),
780782
])
781783
);
@@ -893,6 +895,7 @@ test('nonCancellable', async (t) => {
893895
arguments: toPayloads(defaultPayloadConverter, url),
894896
startToCloseTimeout: msToTs('10m'),
895897
taskQueue: 'test',
898+
doNotEagerlyExecute: false,
896899
}),
897900
])
898901
);
@@ -920,6 +923,7 @@ test('resumeAfterCancellation', async (t) => {
920923
arguments: toPayloads(defaultPayloadConverter, url),
921924
startToCloseTimeout: msToTs('10m'),
922925
taskQueue: 'test',
926+
doNotEagerlyExecute: false,
923927
}),
924928
])
925929
);
@@ -956,6 +960,7 @@ test('handleExternalWorkflowCancellationWhileActivityRunning', async (t) => {
956960
arguments: toPayloads(defaultPayloadConverter, url, data),
957961
startToCloseTimeout: msToTs('10m'),
958962
taskQueue: 'test',
963+
doNotEagerlyExecute: false,
959964
}),
960965
])
961966
);
@@ -980,6 +985,7 @@ test('handleExternalWorkflowCancellationWhileActivityRunning', async (t) => {
980985
arguments: toPayloads(defaultPayloadConverter, url),
981986
startToCloseTimeout: msToTs('10m'),
982987
taskQueue: 'test',
988+
doNotEagerlyExecute: false,
983989
}),
984990
])
985991
);
@@ -1009,6 +1015,7 @@ test('nestedCancellation', async (t) => {
10091015
activityType: 'setup',
10101016
startToCloseTimeout: msToTs('10m'),
10111017
taskQueue: 'test',
1018+
doNotEagerlyExecute: false,
10121019
}),
10131020
])
10141021
);
@@ -1031,6 +1038,7 @@ test('nestedCancellation', async (t) => {
10311038
arguments: toPayloads(defaultPayloadConverter, url, { some: 'data' }),
10321039
startToCloseTimeout: msToTs('10m'),
10331040
taskQueue: 'test',
1041+
doNotEagerlyExecute: false,
10341042
}),
10351043
])
10361044
);
@@ -1053,6 +1061,7 @@ test('nestedCancellation', async (t) => {
10531061
arguments: toPayloads(defaultPayloadConverter, url),
10541062
startToCloseTimeout: msToTs('10m'),
10551063
taskQueue: 'test',
1064+
doNotEagerlyExecute: false,
10561065
}),
10571066
])
10581067
);
@@ -1092,6 +1101,7 @@ test('sharedScopes', async (t) => {
10921101
arguments: toPayloads(defaultPayloadConverter, `http://url${idx}.ninja`),
10931102
startToCloseTimeout: msToTs('10m'),
10941103
taskQueue: 'test',
1104+
doNotEagerlyExecute: false,
10951105
})
10961106
)
10971107
)
@@ -1127,6 +1137,7 @@ test('shieldAwaitedInRootScope', async (t) => {
11271137
arguments: toPayloads(defaultPayloadConverter, `http://example.com`),
11281138
startToCloseTimeout: msToTs('10m'),
11291139
taskQueue: 'test',
1140+
doNotEagerlyExecute: false,
11301141
}),
11311142
])
11321143
);
@@ -1319,6 +1330,7 @@ test('cancelActivityAfterFirstCompletion', async (t) => {
13191330
arguments: toPayloads(defaultPayloadConverter, url),
13201331
startToCloseTimeout: msToTs('10m'),
13211332
taskQueue: 'test',
1333+
doNotEagerlyExecute: false,
13221334
}),
13231335
])
13241336
);
@@ -1339,6 +1351,7 @@ test('cancelActivityAfterFirstCompletion', async (t) => {
13391351
arguments: toPayloads(defaultPayloadConverter, url),
13401352
startToCloseTimeout: msToTs('10m'),
13411353
taskQueue: 'test',
1354+
doNotEagerlyExecute: false,
13421355
}),
13431356
])
13441357
);
@@ -1383,6 +1396,7 @@ test('multipleActivitiesSingleTimeout', async (t) => {
13831396
arguments: toPayloads(defaultPayloadConverter, url),
13841397
startToCloseTimeout: msToTs('1s'),
13851398
taskQueue: 'test',
1399+
doNotEagerlyExecute: false,
13861400
})
13871401
)
13881402
)),
@@ -1423,6 +1437,7 @@ test('resolve activity with result - http', async (t) => {
14231437
arguments: toPayloads(defaultPayloadConverter, 'https://temporal.io'),
14241438
startToCloseTimeout: msToTs('1 minute'),
14251439
taskQueue: 'test',
1440+
doNotEagerlyExecute: false,
14261441
}),
14271442
])
14281443
);
@@ -1457,6 +1472,7 @@ test('resolve activity with failure - http', async (t) => {
14571472
arguments: toPayloads(defaultPayloadConverter, 'https://temporal.io'),
14581473
startToCloseTimeout: msToTs('1 minute'),
14591474
taskQueue: 'test',
1475+
doNotEagerlyExecute: false,
14601476
}),
14611477
])
14621478
);

0 commit comments

Comments
 (0)