I am implementing Amazon SQS for image processing. I wanted to know how can I create a logic in C# that will allow me to only process X amount of images and read more messages to feel the X capacity (let's say 20 images).
From my understanding, I follow this logic for image processing:
- Image uploaded to the server
- I upload the image to S3 for temporary storage with unique string
- I create a SQS message with the image location to be read later on (plus more data that I need to be stored)
- I read the messages on the server
- If there is a message (up to X, let's say 20), run the code that process the image
- The code: download the temp image from S3, process the image, upload it back to S3 processed
What code logic is used in a webservice after the image was uploaded by the user, in order to continuously check for messages and only process X amount of images at a given time. Making sure that if for example one image has completed the process, we can continue to process another one.
e.g. I am processing 20 images, one finished processing, not I can process one more image.
i thought about running the recieveMessageResponse each time a single image processing is complete and keep a counter of the active processes in memory (static variable). So I start with counter = 0, when let's say three images were uploaded, the counter equals to 3. When it reaches 20, I won't process any images, when one finished the counter = counter - 1. I have a if statement that checked the counter, if it's less than X (let's say 20 quota), I will process X - counter.
In my application: the user uploads the image to the EC2 server using a webservice. I have a WCF service that does the processing which is called from the webservice itself. I have a callback function when the image processing is complete.
What is the best logic for it?