Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- for training_id in training_iter {
- let training_id = training_id.map_err(|e| format!("Error pulling worker trainings: {}", e))?;
- // get training from library
- let training = match TRAINING_LIB.with_lock(|lib| lib.get(&training_id.to_string())) {
- // if training is already in library, return i
- Some(training) => training,
- // if training is not in library, pull from database and add to library
- None => {
- match TRAINING_LIB.with_lock(|lib| {
- // pull training from database
- let training = Training::pull_new(&training_id.to_string(), &conn).map_err(|e| format!("Error pulling worker trainings: {}", e));
- // add training to library
- Ok(match training {
- Ok(training) => lib.add(&training_id.to_string(), training),
- Err(e) => {
- return Err(e);
- }
- })
- }) {
- // if training was successfully added to library, return it
- Ok(opt) => match opt {
- Some(training) => training,
- // if training was not found in database, return an error
- None => return Err(format!("Error pulling worker trainings: training with id {} not found", training_id).into()),
- },
- // if training could not be added to library, return an error
- Err(e) => {
- return Err(format!("Error adding training to library: {}", e).into());
- }
- }
- }
- };
- worker_trainings.push(training);
- }
Advertisement
Add Comment
Please, Sign In to add comment