Skip to content

Commit

Permalink
Init jobs table.
Browse files Browse the repository at this point in the history
  • Loading branch information
kirkbyers committed Mar 31, 2024
1 parent 91796e4 commit e587c93
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/db.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use libsql::{Builder, Connection, Database, Error};

use crate::models::{
sm_scrape::INIT_TABLE as SCRAPE_INIT, subscriptions::INIT_TABLE as SUBSCRIPTIONS_INIT,
sm_scrape::INIT_TABLE as SCRAPE_INIT,
subscriptions::INIT_TABLE as SUBSCRIPTIONS_INIT,
jobs::INIT_TABLE as JOBS_INIT,
};

pub async fn local_db(db_path: &str) -> Result<Database, Error> {
Expand All @@ -23,5 +25,6 @@ pub async fn local_db(db_path: &str) -> Result<Database, Error> {
async fn init_schema(conn: &Connection) -> Result<(), Error> {
conn.execute(SUBSCRIPTIONS_INIT, ()).await?;
conn.execute(SCRAPE_INIT, ()).await?;
conn.execute(JOBS_INIT, ()).await?;
Ok(())
}
26 changes: 26 additions & 0 deletions src/models/jobs.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
use serde::{Deserialize, Serialize};

#[derive(Serialize, Deserialize)]
enum JobType {
SMScrape,
Embed
}

#[derive(Serialize, Deserialize)]
enum JobStatus {
Pending,
Running,
Completed,
Failed
}

pub const INIT_TABLE: &str = r#"
CREATE TABLE IF NOT EXISTS jobs (
id uuid NOT NULL PRIMARY KEY,
type INTEGER NOT NULL,
status INTEGER NOT NULL,
created_at timestampz NOT NULL,
updated_at timestampz NOT NULL,
completed_at timestampz,
);
"#;
1 change: 1 addition & 0 deletions src/models/mod.rs
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
pub mod sm_scrape;
pub mod subscriptions;
pub mod jobs;

0 comments on commit e587c93

Please sign in to comment.