Skip to content

Commit e08fc2b

Browse files
author
Mauricio Cassola
committed
Add events table
1 parent ca14859 commit e08fc2b

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

src/db.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ use std::sync::{Arc, Mutex};
55
use tokio::sync::{OwnedSemaphorePermit, Semaphore};
66
use tokio_postgres::Client as DbClient;
77

8+
pub mod events;
89
pub mod issue_data;
910
pub mod notifications;
1011
pub mod rustc_commits;
@@ -215,5 +216,15 @@ CREATE TABLE issue_data (
215216
data JSONB,
216217
PRIMARY KEY (repo, issue_number, key)
217218
);
219+
",
220+
"
221+
CREATE TABLE events (
222+
event_id UUID PRIMARY KEY,
223+
event_name TEXT NOT NULL,
224+
expected_event_time TIMESTAMP WITH TIME ZONE NOT NULL,
225+
event_metadata JSONB,
226+
executed_at TIMESTAMP WITH TIME ZONE NOT NULL,
227+
failed TEXT
228+
);
218229
",
219230
];

src/db/events.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//! The `events` table provides a way to have scheduled events
2+
3+
use anyhow::{Result};
4+
use chrono::{DateTime, FixedOffset};
5+
use tokio_postgres::{Client as DbClient};
6+
use uuid::Uuid;
7+
8+
#[derive(Debug)]
9+
pub struct Event {
10+
pub event_id: Uuid,
11+
pub event_name: String,
12+
pub expected_event_time: DateTime<FixedOffset>,
13+
pub event_metadata: String,
14+
pub executed_at: DateTime<FixedOffset>,
15+
pub failed: Option<String>,
16+
}
17+
18+
pub async fn insert_failed(db: &DbClient) -> Result<()> {
19+
unimplemented!();
20+
}
21+
22+
pub async fn delete_event(db: &DbClient) -> Result<()> {
23+
unimplemented!();
24+
}
25+
26+
pub async fn get_events_to_execute(db: &DbClient) -> Result<Vec<Event>> {
27+
let events = db
28+
.query(
29+
"
30+
SELECT * FROM events",
31+
&[],
32+
)
33+
.await
34+
.unwrap();
35+
36+
Ok(vec![])
37+
}

0 commit comments

Comments
 (0)