create BotInstance::restart_one and restart_all
This commit is contained in:
parent
102fae25c7
commit
308b15ed69
@ -17,6 +17,7 @@ pub struct BotInstance {
|
||||
pub name: String,
|
||||
pub token: String,
|
||||
pub script: String,
|
||||
pub restart_flag: bool,
|
||||
pub created_at: DateTime<FixedOffset>,
|
||||
}
|
||||
|
||||
@ -31,6 +32,7 @@ impl BotInstance {
|
||||
name,
|
||||
token,
|
||||
script,
|
||||
restart_flag: false,
|
||||
created_at: Local::now().into(),
|
||||
}
|
||||
}
|
||||
@ -54,4 +56,23 @@ impl BotInstance {
|
||||
|
||||
Ok(bi.find_one(doc! {"name": name}).await?)
|
||||
}
|
||||
|
||||
pub async fn restart_one<D: CallDB>(db: &mut D, name: &str, restart: bool) -> DbResult<()> {
|
||||
let bi = db.get_collection::<Self>().await;
|
||||
|
||||
bi.update_one(
|
||||
doc! {"name": name},
|
||||
doc! { "$set": { "restart_flag": restart } },
|
||||
)
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn restart_all<D: CallDB>(db: &mut D, restart: bool) -> DbResult<()> {
|
||||
let bi = db.get_collection::<Self>().await;
|
||||
|
||||
bi.update_many(doc! {}, doc! { "$set": { "restart_flag": restart } })
|
||||
.await?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user