diff --git a/typescript/dynamic-workflow-executor/.dockerignore b/typescript/dynamic-workflow-executor/.dockerignore deleted file mode 100644 index 6a9bc407..00000000 --- a/typescript/dynamic-workflow-executor/.dockerignore +++ /dev/null @@ -1,4 +0,0 @@ -.* -node_modules -dist -Dockerfile diff --git a/typescript/dynamic-workflow-executor/Dockerfile b/typescript/dynamic-workflow-executor/Dockerfile deleted file mode 100644 index f9bb1f8f..00000000 --- a/typescript/dynamic-workflow-executor/Dockerfile +++ /dev/null @@ -1,21 +0,0 @@ -FROM node:18-alpine - -# dumb-init helps handling SIGTERM and SIGINT correctly -RUN apk add dumb-init - -WORKDIR /usr/src/app - -# copy package.json and package-lock.json separately to cache dependencies -COPY package*.json . -RUN npm install - -COPY --chown=node:node . . - -RUN npm run build - -RUN npm prune --production -ENV NODE_ENV production - -EXPOSE 9080 -USER node -CMD ["dumb-init", "node", "./dist/app.js"] diff --git a/typescript/dynamic-workflow-executor/README.md b/typescript/dynamic-workflow-executor/README.md index 378fb06f..db98d0bf 100644 --- a/typescript/dynamic-workflow-executor/README.md +++ b/typescript/dynamic-workflow-executor/README.md @@ -21,7 +21,8 @@ Here is an overview of the services: ![](dynamic_workflow_executor.png) -**Note:** This app stores images locally in the `generated-images` folder. These images would of course get lost when the app is restarted. This is just a demo app, so it's not a problem. But in a real app, you would store the images in some persistent storage. +**Note:** This app stores images locally in the shared locally accessible folder `generated-images`. +In a real deployment, this would need to be a shared storage, like S3. ## Running the example @@ -41,27 +42,27 @@ npm install Run puppeteer service: ```shell -npm run puppeteer-dev +npm run puppeteer-service ``` Run transformers service: ```shell -npm run transformers-dev +npm run transformers-service ``` Run stable diffusion service: ```shell -npm run stable-diffusion-dev +npm run stable-diffusion-service ``` Run external stable diffusion service: ```shell -npm run external-stable-diffusion-dev +npm run external-stable-diffusion-service ``` Run workflow service: ```shell -npm run workflow-dev +npm run workflow-service ``` Register the services at the Restate Server, using the CLI: diff --git a/typescript/dynamic-workflow-executor/package.json b/typescript/dynamic-workflow-executor/package.json index 15beb642..3cf2c2b2 100644 --- a/typescript/dynamic-workflow-executor/package.json +++ b/typescript/dynamic-workflow-executor/package.json @@ -2,20 +2,17 @@ "name": "dynamic-workflow-executor", "version": "0.0.1", "description": "An application that executes a workflow based on a workflow definition", - "main": "app.js", + "author": "Restate Developers", + "license": "MIT", + "email": "code@restate.dev", "type": "commonjs", "scripts": { "build": "tsc --noEmitOnError", - "prebundle": "rm -rf dist", - "bundle": "esbuild src/app.ts --bundle --minify --sourcemap --platform=node --target=es2020 --outfile=dist/index.js", - "postbundle": "cd dist && zip -r index.zip index.js*", - "app": "node ./dist/app.js", - "app-dev": "ts-node-dev --watch ./src --respawn --transpile-only ./src/app.ts", - "puppeteer-dev": "ts-node-dev --watch ./src --respawn --transpile-only src/puppeteer/puppeteer.ts", - "stable-diffusion-dev": "ts-node-dev --watch ./src --respawn --transpile-only src/stable-diffusion/stable_diffusion.ts", - "external-stable-diffusion-dev": "ts-node-dev --watch ./src --respawn --transpile-only src/external/stable_diffusion.ts", - "transformers-dev": "ts-node-dev --watch ./src --respawn --transpile-only src/transformers/transformers.ts", - "workflow-dev": "ts-node-dev --watch ./src --respawn --transpile-only src/workflow/workflow.ts" + "puppeteer-service": "ts-node-dev --watch ./src --respawn --transpile-only src/puppeteer/puppeteer.ts", + "stable-diffusion-service": "ts-node-dev --watch ./src --respawn --transpile-only src/stable-diffusion/stable_diffusion.ts", + "external-stable-diffusion-service": "ts-node-dev --watch ./src --respawn --transpile-only src/external/stable_diffusion.ts", + "transformers-service": "ts-node-dev --watch ./src --respawn --transpile-only src/transformers/transformers.ts", + "workflow-service": "ts-node-dev --watch ./src --respawn --transpile-only src/workflow/workflow.ts" }, "dependencies": { "@restatedev/restate-sdk": "^0.7.0", diff --git a/typescript/dynamic-workflow-executor/src/transformers/blur_img_service.ts b/typescript/dynamic-workflow-executor/src/transformers/blur_img_service.ts index bd4fa630..9493db10 100644 --- a/typescript/dynamic-workflow-executor/src/transformers/blur_img_service.ts +++ b/typescript/dynamic-workflow-executor/src/transformers/blur_img_service.ts @@ -9,6 +9,14 @@ export const router = restate.router({ const blurParams = wfStep.parameters as { blur: number }; console.info("Blurring image with parameters: " + JSON.stringify(blurParams)) + // we don't want to retry this too often, because failures here are most likely + // terminal (path issues, etc.), so limit the reties to 5 + const retrySettings = { + initialDelayMs: 100, + maxRetries: 5, + name: "image blurring" + }; + await ctx.sideEffect(async () => { let image; try { @@ -18,7 +26,7 @@ export const router = restate.router({ } const blurredImg = image.blur(blurParams.blur); await blurredImg.writeAsync(wfStep.imgOutputPath!) - }) + }, retrySettings); return { msg: "[Blurred image with parameters: " + JSON.stringify(blurParams) + "]" diff --git a/typescript/dynamic-workflow-executor/src/transformers/rotate_img_service.ts b/typescript/dynamic-workflow-executor/src/transformers/rotate_img_service.ts index 6f8d0518..fe7a1450 100644 --- a/typescript/dynamic-workflow-executor/src/transformers/rotate_img_service.ts +++ b/typescript/dynamic-workflow-executor/src/transformers/rotate_img_service.ts @@ -8,6 +8,14 @@ export const router = restate.router({ const rotateParams = wfStep.parameters as { angle: number }; console.info("Rotating image with parameters: " + JSON.stringify(rotateParams)) + // we don't want to retry this too often, because failures here are most likely + // terminal (path issues, etc.), so limit the reties to 5 + const retrySettings = { + initialDelayMs: 100, + maxRetries: 5, + name: "image blurring" + }; + await ctx.sideEffect(async () => { let image; try { @@ -17,7 +25,7 @@ export const router = restate.router({ } const rotatedImg = image.rotate(rotateParams.angle); await rotatedImg.writeAsync(wfStep.imgOutputPath!) - }) + }, retrySettings); return { msg: "[Rotated image with parameters: " + JSON.stringify(rotateParams) + "]"