Skip to content

Commit f6687a6

Browse files
author
remote-swe-app[bot]
committed
docs: add asynchronous jobs section to webapp README
1 parent dad0742 commit f6687a6

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

webapp/README.md

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,3 +185,68 @@ This project uses type-safe server actions with authentication:
185185
);
186186
}
187187
```
188+
189+
### Asynchronous Jobs
190+
191+
Asynchronous jobs are Lambda functions that handle long-running or background tasks. The `job.Dockerfile` builds all TypeScript files in `src/jobs/` into separate Lambda handlers using `esbuild src/jobs/*.ts --bundle`.
192+
193+
**Project structure:**
194+
195+
For simple jobs, place a single file directly under `src/jobs/`:
196+
197+
```
198+
webapp/src/jobs/
199+
├── migration-runner.ts # Single-file Lambda handler
200+
└── async-job-runner.ts # Single-file Lambda handler
201+
```
202+
203+
For jobs with complex logic, use a subdirectory:
204+
205+
```
206+
webapp/src/jobs/
207+
├── async-job-runner.ts # Lambda handler entry point
208+
└── async-job/ # Business logic directory
209+
└── translate.ts # Job implementation
210+
```
211+
212+
**Example implementation:**
213+
214+
```typescript
215+
// webapp/src/jobs/async-job-runner.ts
216+
import { translateJobHandler, translateJobSchema } from '@/jobs/async-job/translate';
217+
import { Handler } from 'aws-lambda';
218+
import { z } from 'zod';
219+
220+
const jobPayloadPropsSchema = z.discriminatedUnion('type', [
221+
translateJobSchema,
222+
// Add more job types here
223+
]);
224+
225+
export const handler: Handler<unknown> = async (event) => {
226+
const { data: payload, error } = jobPayloadPropsSchema.safeParse(event);
227+
if (error) throw new Error(error.toString());
228+
229+
switch (payload.type) {
230+
case 'translate':
231+
await translateJobHandler(payload);
232+
break;
233+
}
234+
};
235+
```
236+
237+
```typescript
238+
// webapp/src/jobs/async-job/translate.ts
239+
import { z } from 'zod';
240+
241+
export const translateJobSchema = z.object({
242+
type: z.literal('translate'),
243+
todoItemId: z.string(),
244+
userId: z.string(),
245+
});
246+
247+
export const translateJobHandler = async (params: z.infer<typeof translateJobSchema>) => {
248+
// Job implementation
249+
};
250+
```
251+
252+
**Note:** All jobs share the same `job.Dockerfile`. No individual Dockerfiles are needed. To deploy jobs, configure them in the CDK stack (see `cdk/lib/constructs/async-job.ts`).

0 commit comments

Comments
 (0)