rebuilderd_common/api/v1/models/
queue.rs1use crate::api::v1::{BuildStatus, Priority};
2use chrono::{DateTime, NaiveDateTime, Utc};
3#[cfg(feature = "diesel")]
4use diesel::Queryable;
5use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Serialize, Deserialize)]
8pub struct QueueJobRequest {
9 pub distribution: Option<String>,
10 pub release: Option<String>,
11 pub component: Option<String>,
12 pub name: Option<String>,
13 pub version: Option<String>,
14 pub architecture: Option<String>,
15 pub status: Option<BuildStatus>,
16 pub priority: Option<Priority>,
17}
18
19#[derive(Debug, Serialize, Deserialize)]
20pub struct PopQueuedJobRequest {
21 pub supported_backends: Vec<String>,
22 pub architecture: String,
23 pub supported_architectures: Vec<String>,
24}
25
26#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
27#[cfg_attr(feature = "diesel", derive(Queryable))]
28#[cfg_attr(feature = "diesel", diesel(check_for_backend(diesel::sqlite::Sqlite)))]
29pub struct QueuedJob {
30 pub id: i32,
31 pub name: String,
32 pub version: String,
33 pub distribution: String,
34 pub release: Option<String>,
35 pub component: Option<String>,
36 pub architecture: String,
37 pub backend: String,
38 pub url: String,
39 pub next_retry: Option<NaiveDateTime>,
40 pub priority: Priority,
41 pub queued_at: NaiveDateTime,
42 pub started_at: Option<NaiveDateTime>,
43}
44
45impl QueuedJob {
46 pub fn is_due(&self, now: DateTime<Utc>) -> bool {
47 if let Some(next_retry) = self.next_retry {
48 next_retry <= now.naive_utc()
49 } else {
50 true
51 }
52 }
53
54 pub fn running_since(&self, now: DateTime<Utc>) -> Option<chrono::TimeDelta> {
55 let started_at = self.started_at?;
56 let duration = now.naive_utc() - started_at;
57 Some(duration)
58 }
59}
60
61#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
62#[cfg_attr(feature = "diesel", derive(Queryable))]
63#[cfg_attr(feature = "diesel", diesel(check_for_backend(diesel::sqlite::Sqlite)))]
64pub struct QueuedJobArtifact {
65 pub name: String,
66 pub version: String,
67 pub architecture: String,
68 pub url: String,
69}
70
71#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
72pub struct QueuedJobWithArtifacts {
73 pub job: QueuedJob,
74 pub artifacts: Vec<QueuedJobArtifact>,
75}
76
77#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
78pub enum JobAssignment {
79 Nothing,
80 Rebuild(Box<QueuedJobWithArtifacts>),
81}