Skip to content

Commit 5e4a5c3

Browse files
committed
Lint
1 parent 3dcc150 commit 5e4a5c3

File tree

5 files changed

+97
-76
lines changed

5 files changed

+97
-76
lines changed

packages/common/src/converter/failure-converter.ts

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,20 @@ const NexusHandlerErrorRetryBehavior = {
3232
type NexusHandlerErrorRetryBehavior =
3333
(typeof NexusHandlerErrorRetryBehavior)[keyof typeof NexusHandlerErrorRetryBehavior];
3434

35-
const [encodeNexusHandlerErrorRetryBehavior, decodeNexusHandlerErrorRetryBehavior] =
36-
makeProtoEnumConverters<
37-
temporal.api.enums.v1.NexusHandlerErrorRetryBehavior,
38-
typeof temporal.api.enums.v1.NexusHandlerErrorRetryBehavior,
39-
keyof typeof temporal.api.enums.v1.NexusHandlerErrorRetryBehavior,
40-
typeof NexusHandlerErrorRetryBehavior,
41-
'NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_'
42-
>(
43-
{
44-
UNSPECIFIED: 0,
45-
[NexusHandlerErrorRetryBehavior.RETRYABLE]: 1,
46-
[NexusHandlerErrorRetryBehavior.NON_RETRYABLE]: 2,
47-
} as const,
48-
'NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_'
49-
);
35+
const [encodeNexusHandlerErrorRetryBehavior, decodeNexusHandlerErrorRetryBehavior] = makeProtoEnumConverters<
36+
temporal.api.enums.v1.NexusHandlerErrorRetryBehavior,
37+
typeof temporal.api.enums.v1.NexusHandlerErrorRetryBehavior,
38+
keyof typeof temporal.api.enums.v1.NexusHandlerErrorRetryBehavior,
39+
typeof NexusHandlerErrorRetryBehavior,
40+
'NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_'
41+
>(
42+
{
43+
UNSPECIFIED: 0,
44+
[NexusHandlerErrorRetryBehavior.RETRYABLE]: 1,
45+
[NexusHandlerErrorRetryBehavior.NON_RETRYABLE]: 2,
46+
} as const,
47+
'NEXUS_HANDLER_ERROR_RETRY_BEHAVIOR_'
48+
);
5049

5150
function combineRegExp(...regexps: RegExp[]): RegExp {
5251
return new RegExp(regexps.map((x) => `(?:${x.source})`).join('|'));
@@ -379,9 +378,9 @@ export class DefaultFailureConverter implements FailureConverter {
379378
if (err instanceof nexus.HandlerError) {
380379
let retryBehavior: temporal.api.enums.v1.NexusHandlerErrorRetryBehavior | undefined = undefined;
381380
if (err.retryable === true) {
382-
retryBehavior = encodeNexusHandlerErrorRetryBehavior("RETRYABLE");
381+
retryBehavior = encodeNexusHandlerErrorRetryBehavior('RETRYABLE');
383382
} else if (err.retryable === false) {
384-
retryBehavior = encodeNexusHandlerErrorRetryBehavior("NON_RETRYABLE");
383+
retryBehavior = encodeNexusHandlerErrorRetryBehavior('NON_RETRYABLE');
385384
}
386385

387386
return {

packages/test/src/test-nexus-handler.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,13 @@ import * as temporalnexus from '@temporalio/nexus';
77
import * as root from '@temporalio/proto';
88
import * as testing from '@temporalio/testing';
99
import { DefaultLogger, LogEntry, Runtime, Worker } from '@temporalio/worker';
10-
import { ApplicationFailure, CancelledFailure, defaultFailureConverter, defaultPayloadConverter, SdkComponent } from '@temporalio/common';
10+
import {
11+
ApplicationFailure,
12+
CancelledFailure,
13+
defaultFailureConverter,
14+
defaultPayloadConverter,
15+
SdkComponent,
16+
} from '@temporalio/common';
1117
import { cleanStackTrace } from './helpers';
1218

1319
export interface Context {

packages/test/src/test-nexus-link-converter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test('convertNexusLinkToLinkWorkflowEvent with an event type in PascalCase', (t)
5959
'temporal:///namespaces/ns2/workflows/wid2/rid2/history?referenceType=RequestIdReference&requestID=req-123&eventType=WorkflowTaskCompleted'
6060
),
6161
type: WORKFLOW_EVENT_TYPE,
62-
}
62+
};
6363

6464
const workflowEventLink = convertNexusLinkToWorkflowEventLink(nexusLink);
6565
t.is(workflowEventLink.requestIdRef?.eventType, EventType.EVENT_TYPE_WORKFLOW_TASK_COMPLETED);

packages/worker/src/nexus/index.ts

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,11 @@ import {
1515
} from '@temporalio/common';
1616
import { temporal, coresdk } from '@temporalio/proto';
1717
import { HandlerContext } from '@temporalio/nexus/lib/context';
18-
import { encodeToPayload, encodeErrorToFailure, decodeOptionalSingle } from '@temporalio/common/lib/internal-non-workflow';
18+
import {
19+
encodeToPayload,
20+
encodeErrorToFailure,
21+
decodeOptionalSingle,
22+
} from '@temporalio/common/lib/internal-non-workflow';
1923
import { fixBuffers } from '@temporalio/common/lib/proto-utils';
2024
import { isAbortError } from '@temporalio/common/lib/type-helpers';
2125
import { isGrpcServiceError, ServiceError } from '@temporalio/client';
@@ -122,9 +126,12 @@ export class NexusHandler {
122126
// empty Content.
123127
const input = new nexus.LazyValue(
124128
new PayloadSerializer(this.dataConverter.payloadConverter, decoded ?? undefined),
125-
{},
129+
{}
130+
);
131+
const result = await this.invokeUserCode(
132+
'startOperation',
133+
this.serviceRegistry.start.bind(this.serviceRegistry, this.info.service, this.info.operation, input, options)
126134
);
127-
const result = await this.invokeUserCode('startOperation', this.serviceRegistry.start.bind(this.serviceRegistry, this.info.service, this.info.operation, input, options));
128135
if (isAsyncResult(result)) {
129136
return {
130137
taskToken: this.taskToken,
@@ -180,7 +187,10 @@ export class NexusHandler {
180187
options: nexus.CancelOperationOptions
181188
): Promise<coresdk.nexus.INexusTaskCompletion> {
182189
try {
183-
await this.invokeUserCode('cancelOperation', this.serviceRegistry.cancel.bind(this.serviceRegistry, this.info.service, this.info.operation, token, options));
190+
await this.invokeUserCode(
191+
'cancelOperation',
192+
this.serviceRegistry.cancel.bind(this.serviceRegistry, this.info.service, this.info.operation, token, options)
193+
);
184194
return {
185195
taskToken: this.taskToken,
186196
completed: {
@@ -340,11 +350,11 @@ function convertKnownErrors(err: unknown): nexus.HandlerError {
340350
case (status.ABORTED, status.UNAVAILABLE):
341351
return new nexus.HandlerError({ type: 'UNAVAILABLE', cause: err });
342352
case (status.CANCELLED,
343-
status.DATA_LOSS,
344-
status.INTERNAL,
345-
status.UNKNOWN,
346-
status.UNAUTHENTICATED,
347-
status.PERMISSION_DENIED):
353+
status.DATA_LOSS,
354+
status.INTERNAL,
355+
status.UNKNOWN,
356+
status.UNAUTHENTICATED,
357+
status.PERMISSION_DENIED):
348358
// Note that UNAUTHENTICATED and PERMISSION_DENIED have Nexus error types but we convert to internal because
349359
// this is not a client auth error and happens when the handler fails to auth with Temporal and should be
350360
// considered retryable.
@@ -420,8 +430,8 @@ function nexusLinkToProtoLink(nlink: nexus.Link): temporal.api.nexus.v1.ILink {
420430
class PayloadSerializer implements nexus.Serializer {
421431
constructor(
422432
readonly payloadConverter: PayloadConverter,
423-
readonly payload?: Payload,
424-
) { }
433+
readonly payload?: Payload
434+
) {}
425435

426436
deserialize<T>(): T {
427437
if (this.payload == null) {
@@ -432,6 +442,6 @@ class PayloadSerializer implements nexus.Serializer {
432442

433443
/** Not used in this path */
434444
serialize(): nexus.Content {
435-
throw new Error("not implemented");
445+
throw new Error('not implemented');
436446
}
437447
}

packages/worker/src/worker.ts

Lines changed: 51 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -492,11 +492,11 @@ export class Worker {
492492
...compiledOptions,
493493
...(compiledOptions.workflowBundle && isCodeBundleOption(compiledOptions.workflowBundle)
494494
? {
495-
// Avoid dumping workflow bundle code to the console
496-
workflowBundle: <WorkflowBundle>{
497-
code: `<string of length ${compiledOptions.workflowBundle.code.length}>`,
498-
},
499-
}
495+
// Avoid dumping workflow bundle code to the console
496+
workflowBundle: <WorkflowBundle>{
497+
code: `<string of length ${compiledOptions.workflowBundle.code.length}>`,
498+
},
499+
}
500500
: {}),
501501
},
502502
});
@@ -710,7 +710,7 @@ export class Worker {
710710
) {
711711
logger.warn(
712712
'Ignoring WorkerOptions.interceptors.workflowModules because WorkerOptions.workflowBundle is set.\n' +
713-
'To use workflow interceptors with a workflowBundle, pass them in the call to bundleWorkflowCode.'
713+
'To use workflow interceptors with a workflowBundle, pass them in the call to bundleWorkflowCode.'
714714
);
715715
}
716716

@@ -883,8 +883,8 @@ export class Worker {
883883
*/
884884
protected pollLoop$<T>(pollFn: () => Promise<T>): Observable<T> {
885885
return from(
886-
(async function*() {
887-
for (; ;) {
886+
(async function* () {
887+
for (;;) {
888888
try {
889889
yield await pollFn();
890890
} catch (err) {
@@ -919,14 +919,14 @@ export class Worker {
919919
// so it can be cancelled if requested
920920
let output:
921921
| {
922-
type: 'result';
923-
result: coresdk.activity_result.IActivityExecutionResult;
924-
}
922+
type: 'result';
923+
result: coresdk.activity_result.IActivityExecutionResult;
924+
}
925925
| {
926-
type: 'run';
927-
activity: Activity;
928-
input: ActivityExecuteInput;
929-
}
926+
type: 'run';
927+
activity: Activity;
928+
input: ActivityExecuteInput;
929+
}
930930
| { type: 'ignore' };
931931
switch (variant) {
932932
case 'start': {
@@ -1112,38 +1112,44 @@ export class Worker {
11121112
*/
11131113
protected nexusOperator(): OperatorFunction<NexusTaskWithBase64Token, Uint8Array> {
11141114
return pipe(
1115-
mergeMap(async ({ task, base64TaskToken, protobufEncodedTask }): Promise<coresdk.nexus.INexusTaskCompletion | undefined> => {
1116-
const { variant } = task;
1117-
if (!variant) {
1118-
throw new TypeError('Got a nexus task without a "variant" attribute');
1119-
}
1120-
1121-
switch (variant) {
1122-
case 'task': {
1123-
if (task.task == null) {
1124-
throw new IllegalStateError(`Got empty task for task variant with token: ${base64TaskToken}`);
1125-
}
1126-
return await this.handleNexusRunTask(task.task, base64TaskToken, protobufEncodedTask);
1115+
mergeMap(
1116+
async ({
1117+
task,
1118+
base64TaskToken,
1119+
protobufEncodedTask,
1120+
}): Promise<coresdk.nexus.INexusTaskCompletion | undefined> => {
1121+
const { variant } = task;
1122+
if (!variant) {
1123+
throw new TypeError('Got a nexus task without a "variant" attribute');
11271124
}
1128-
case 'cancelTask': {
1129-
const nexusHandler = this.taskTokenToNexusHandler.get(base64TaskToken);
1130-
if (nexusHandler == null) {
1131-
this.logger.trace('Tried to cancel a non-existing nexus handler', {
1132-
taskToken: base64TaskToken,
1133-
});
1134-
break;
1125+
1126+
switch (variant) {
1127+
case 'task': {
1128+
if (task.task == null) {
1129+
throw new IllegalStateError(`Got empty task for task variant with token: ${base64TaskToken}`);
1130+
}
1131+
return await this.handleNexusRunTask(task.task, base64TaskToken, protobufEncodedTask);
11351132
}
1136-
// NOTE: nexus handler will not be considered cancelled until it confirms cancellation (by throwing a CancelledFailure)
1137-
this.logger.trace('Cancelling nexus handler', nexusLogAttributes(nexusHandler.info));
1138-
let reason = 'unkown';
1139-
if (task.cancelTask?.reason != null) {
1140-
reason = coresdk.nexus.NexusTaskCancelReason[task.cancelTask.reason];
1133+
case 'cancelTask': {
1134+
const nexusHandler = this.taskTokenToNexusHandler.get(base64TaskToken);
1135+
if (nexusHandler == null) {
1136+
this.logger.trace('Tried to cancel a non-existing nexus handler', {
1137+
taskToken: base64TaskToken,
1138+
});
1139+
break;
1140+
}
1141+
// NOTE: nexus handler will not be considered cancelled until it confirms cancellation (by throwing a CancelledFailure)
1142+
this.logger.trace('Cancelling nexus handler', nexusLogAttributes(nexusHandler.info));
1143+
let reason = 'unkown';
1144+
if (task.cancelTask?.reason != null) {
1145+
reason = coresdk.nexus.NexusTaskCancelReason[task.cancelTask.reason];
1146+
}
1147+
nexusHandler.abortController.abort(new CancelledFailure(reason));
1148+
return { ackCancel: true, taskToken: task.cancelTask?.taskToken };
11411149
}
1142-
nexusHandler.abortController.abort(new CancelledFailure(reason));
1143-
return { ackCancel: true, taskToken: task.cancelTask?.taskToken }
11441150
}
11451151
}
1146-
}),
1152+
),
11471153
filter(<T>(result: T): result is Exclude<T, undefined> => result !== undefined),
11481154
map((result) => coresdk.nexus.NexusTaskCompletion.encodeDelimited(result).finish())
11491155
);
@@ -1278,9 +1284,9 @@ export class Worker {
12781284
const completion = synthetic
12791285
? undefined
12801286
: coresdk.workflow_completion.WorkflowActivationCompletion.encodeDelimited({
1281-
runId: activation.runId,
1282-
successful: {},
1283-
}).finish();
1287+
runId: activation.runId,
1288+
successful: {},
1289+
}).finish();
12841290
return { state: undefined, output: { close, completion } };
12851291
}
12861292

0 commit comments

Comments
 (0)