Skip to content

Commit 05fd2f3

Browse files
authored
Introduce lambda worker sample (#455)
1 parent ccce6e2 commit 05fd2f3

30 files changed

Lines changed: 1303 additions & 391 deletions

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,7 @@ package-lock.json
111111
*/**/pnpm-lock.yaml
112112

113113
.idea/
114+
115+
**/client.key
116+
**/client.pem
117+
worker-versioning/.claude/settings.local.json

.scripts/copy-shared-files.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ const TSCONFIG_EXCLUDE = [
2525
'production',
2626
'hello-world-js',
2727
'food-delivery',
28+
'lambda-worker',
2829
'nestjs-exchange-rates',
2930
'empty',
3031
'hello-world',
@@ -37,6 +38,7 @@ const GITIGNORE_EXCLUDE = [
3738
'hello-world-js',
3839
'protobufs',
3940
'food-delivery',
41+
'lambda-worker',
4042
'nestjs-exchange-rates',
4143
];
4244
const ESLINTRC_EXCLUDE = [
@@ -71,6 +73,7 @@ const POST_CREATE_EXCLUDE = [
7173
'patching-api',
7274
'signals-queries',
7375
'activities-cancellation-heartbeating',
76+
'lambda-worker',
7477
'nestjs-exchange-rates',
7578
'food-delivery',
7679
'search-attributes',

.scripts/list-of-samples.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"hello-world-js",
2525
"hello-world-mtls",
2626
"interceptors-opentelemetry",
27+
"lambda-worker",
2728
"monorepo-folders",
2829
"mutex",
2930
"nestjs-exchange-rates",

cron-workflows/src/activities.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@ import { log, activityInfo } from '@temporalio/activity';
22

33
export async function logTime(name: string, wfTime: string): Promise<void> {
44
const { workflowExecution } = activityInfo();
5-
log.info(`Hello from ${workflowExecution.workflowId}, ${name}!`, { workflowTime: wfTime, activityTime: Date.now() });
5+
log.info(`Hello from ${workflowExecution?.workflowId}, ${name}!`, { workflowTime: wfTime, activityTime: Date.now() });
66
}

food-delivery/packages/activities/services.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export const notificationService = {
1313
export const paymentService = {
1414
charge(cents: number) {
1515
// In a real app, we would pass an idempotency token to the downstream service
16-
const _idempotencyToken = `${activityInfo().workflowExecution.workflowId}-charge`
16+
const _idempotencyToken = `${activityInfo().workflowExecution!.workflowId}-charge`
1717
if (cents >= 3500) {
1818
throw ApplicationFailure.create({ nonRetryable: true, message: 'Card declined: insufficient funds' })
1919
}
@@ -25,7 +25,7 @@ export const paymentService = {
2525

2626
refund(cents: number) {
2727
// In a real app, we would pass an idempotency token to the downstream service
28-
const _idempotencyToken = `${activityInfo().workflowExecution.workflowId}-refund`
28+
const _idempotencyToken = `${activityInfo().workflowExecution!.workflowId}-refund`
2929
if (Math.random() < 0.7) {
3030
throw new Error('Failed to refund. Unable to reach payment service.')
3131
}

lambda-worker/.eslintignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules
2+
lib
3+
.eslintrc.js

lambda-worker/.eslintrc.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
const { builtinModules } = require('module');
2+
3+
const ALLOWED_NODE_BUILTINS = new Set(['assert']);
4+
5+
module.exports = {
6+
root: true,
7+
parser: '@typescript-eslint/parser',
8+
parserOptions: {
9+
project: './tsconfig.json',
10+
tsconfigRootDir: __dirname,
11+
},
12+
plugins: ['@typescript-eslint', 'deprecation'],
13+
extends: [
14+
'eslint:recommended',
15+
'plugin:@typescript-eslint/eslint-recommended',
16+
'plugin:@typescript-eslint/recommended',
17+
'prettier',
18+
],
19+
rules: {
20+
// recommended for safety
21+
'@typescript-eslint/no-floating-promises': 'error', // forgetting to await Activities and Workflow APIs is bad
22+
'deprecation/deprecation': 'warn',
23+
24+
// code style preference
25+
'object-shorthand': ['error', 'always'],
26+
27+
// relaxed rules, for convenience
28+
'@typescript-eslint/no-unused-vars': [
29+
'warn',
30+
{
31+
argsIgnorePattern: '^_',
32+
varsIgnorePattern: '^_',
33+
},
34+
],
35+
'@typescript-eslint/no-explicit-any': 'off',
36+
},
37+
overrides: [
38+
{
39+
files: ['src/workflows.ts', 'src/workflows-*.ts', 'src/workflows/*.ts'],
40+
rules: {
41+
'no-restricted-imports': [
42+
'error',
43+
...builtinModules.filter((m) => !ALLOWED_NODE_BUILTINS.has(m)).flatMap((m) => [m, `node:${m}`]),
44+
],
45+
},
46+
},
47+
],
48+
};

lambda-worker/.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
lib
2+
node_modules
3+
workflow-bundle.js
4+
function.zip
5+
package/

lambda-worker/.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

lambda-worker/.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
22

0 commit comments

Comments
 (0)