Uploading a video post and process using a worker
In this section, we are going to process an uploaded video. Processing an uploaded video is not a trivial task as it can take a lot of time, so even with the async
programming technique, the generated response will take a lot of time.
Another technique in programming to solve a long processing time is using message passing. We are going to create another thread to process the video. When a user uploads a video, we will do the following:
- Generate a path to the temporary file.
- Mark the path as unprocessed.
- Store the path to the file in the database.
- Send a message from the main Rocket thread into the thread for processing the video.
- Return the response for uploading the video.
If the thread to process the video receives a message, it will find the data from the database, process the file, and mark the post as finished.
If the user requests the posts
list or posts while it's still being processed...