2 个版本
0.1.1 | 2023 年 2 月 16 日 |
---|---|
0.1.0 | 2023 年 2 月 15 日 |
11 in #job-processing
46KB
837 代码行,不包括注释
松饼
松饼是一个后台任务处理库,旨在与 MongoDB 一起使用作为其存储后端。
需要 MongoDB 6,并将功能兼容级别设置为 6
。
示例
// Connect to a database called "muffin_testing".
let client = Client::with_uri_str("mongodb://127.0.0.1:27017").await?;
let database = client.database("muffin_testing");
// The state is passed to each "process" method on an instance of Job.
let state = JobState {
mongo_client: client,
};
let mut muffin = Muffin::new(database, Arc::new(state)).await?;
// Create a new job and push it for processing
muffin
.push(MyJob {
name: "Peter".into(),
})
.await?;
// Register jobs that should be processed.
muffin.register::<MyJob>();
// Start processing jobs.
tokio::select! {
_ = muffin.run() => {},
_ = tokio::signal::ctrl_c() => {
eprintln!("Received ctrl+c!");
}
};
// Need to wait for all in-flight jobs to finish processing.
muffin.shutdown().await;
许可证
- MIT 许可证
依赖项
~24–36MB
~671K SLoC