Since parallel steps are not yet available in
workflow-py, Python example is implemented in a sequential manner. See our
Roadmap for feature parity plans and
Changelog for updates.
This example demonstrates how to process images using Upstash Workflow. The following workflow will upload an image, resize it into multiple resolutions, apply filters, and store the processed versions for later retrieval.
After resizing, we apply filters such as grayscale, sepia, and contrast to the resized images.
Again, we call context.call for each filter & image pair. We collect the promises of these requests in an array processedImagePromise. Then, we call Promise.all again to run them all parallel.
const filters =["grayscale","sepia","contrast"]const processedImagePromises:Promise<string>[]=[]for(const resizedImage of resizedImages){for(const filter of filters){const processedImagePromise = context.call<ImageResult>(`apply-filter-${filter}`,{// endpoint which returns ImageResult type in response url:"https://image-processing-service.com/filter", method:"POST", body:{ imageUrl: resizedImage.body.imageUrl, filter,}}) processedImagePromises.push(processedImagePromise)}}const processedImages:{ body: ImageResult }[]=awaitPromise.all(processedImagePromises)
Batch Processing: This workflow handles batch resizing and filtering of images in parallel to minimize processing time.
Scalability: Image resizing and filtering are handled through external services, making it easy to scale. Also, the requests to these services are handled by QStash, not by the compute where the workflow is hosted.
Storage Integration: The workflow integrates with cloud storage to persist processed images for future access.