Defining messages for the Redis queue
To support multiple tasks, we must do a two-step approach to packaging our tasks to be inserted into the Redis queue. This means that we will serialize the task struct into Vec<u8>
, then add this vector of bytes to another struct that has a field denoting what type of task is in the message. We can define this process by first importing the Serialize
and Deserialize
traits in the src/tasks/mod.rs
file with the following code:
use serde::{Serialize, Deserialize};
We can then define the enum
task type and message struct with the following code:
#[derive(Debug, Clone, Serialize, Deserialize)] use add::AddTask; use multiply::MultiplyTask; use subtract::SubtractTask; #[derive(Debug, Clone, Serialize, Deserialize)] pub enum TaskType { ADD(AddTask), MULTIPLY(MultiplyTask), SUBTRACT(SubtractTask) } #[derive(Debug, Clone, Serialize, Deserialize)] pub struct TaskMessage...