• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

divviup / divviup-api / 8666760397

12 Apr 2024 07:02PM UTC coverage: 56.289% (+0.2%) from 56.083%
8666760397

Pull #968

github

web-flow
Merge 8c0857084 into a6cdbab81
Pull Request #968: Support for time bucketed fixed size

58 of 86 new or added lines in 8 files covered. (67.44%)

6 existing lines in 5 files now uncovered.

3692 of 6559 relevant lines covered (56.29%)

102.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

61.22
/src/routes/admin.rs
1
use crate::{
2
    entity::queue::{self, Column, Entity, JobStatus, Model},
3
    handler::{admin_required, Error},
4
    Db,
5
};
6
use querystrong::QueryStrong;
7
use sea_orm::{ColumnTrait, EntityTrait, ModelTrait, QueryOrder, QuerySelect};
8
use trillium::{async_trait, Conn, Handler, Status};
9
use trillium_api::{api, FromConn, Json};
10
use trillium_caching_headers::CachingHeadersExt;
11
use trillium_router::{router, RouterConnExt};
12
use uuid::Uuid;
13

14
pub fn routes() -> impl Handler {
268✔
15
    (
268✔
16
        api(admin_required),
268✔
17
        router()
268✔
18
            .get("/queue", api(index))
268✔
19
            .get("/queue/:job_id", api(show))
268✔
20
            .delete("/queue/:job_id", api(delete)),
268✔
21
    )
268✔
22
}
268✔
23

24
#[async_trait]
25
impl FromConn for queue::Model {
26
    async fn from_conn(conn: &mut Conn) -> Option<Self> {
×
27
        let db = Db::from_conn(conn).await?;
×
28
        let id: Uuid = conn.param("job_id")?.parse().ok()?;
×
29

30
        match Entity::find_by_id(id).one(&db).await {
×
31
            Ok(job) => job,
×
32
            Err(error) => {
×
33
                conn.set_state(Error::from(error));
×
34
                None
×
35
            }
36
        }
37
    }
×
38
}
39

40
async fn index(conn: &mut Conn, db: Db) -> Result<Json<Vec<Model>>, Error> {
4✔
41
    let params = QueryStrong::parse(conn.querystring()).unwrap_or_default();
4✔
42
    let mut find = Entity::find();
4✔
43
    let query = QuerySelect::query(&mut find);
4✔
44
    match params.get_str("status") {
4✔
45
        Some("pending") => {
3✔
46
            query.cond_where(Column::Status.eq(JobStatus::Pending));
1✔
47
        }
1✔
48

49
        Some("success") => {
2✔
50
            query.cond_where(Column::Status.eq(JobStatus::Success));
1✔
51
        }
1✔
52

53
        Some("failed") => {
1✔
54
            query.cond_where(Column::Status.eq(JobStatus::Failed));
1✔
55
        }
1✔
56

57
        _ => {}
1✔
58
    }
59

60
    find.order_by_desc(Column::UpdatedAt)
4✔
61
        .limit(100)
4✔
62
        .all(&db)
4✔
UNCOV
63
        .await
×
64
        .map(Json)
4✔
65
        .map_err(Error::from)
4✔
66
}
4✔
67

68
async fn show(conn: &mut Conn, queue_job: Model) -> Json<Model> {
×
69
    conn.set_last_modified(queue_job.updated_at.into());
×
70

×
71
    Json(queue_job)
×
72
}
×
73

74
async fn delete(_: &mut Conn, (queue_job, db): (Model, Db)) -> Result<Status, Error> {
×
75
    queue_job.delete(&db).await?;
×
76
    Ok(Status::NoContent)
×
77
}
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc