Skip to content

Commit

Permalink
SQL queue system
Browse files Browse the repository at this point in the history
  • Loading branch information
randommm committed Nov 20, 2023
1 parent ad6753c commit 327116c
Show file tree
Hide file tree
Showing 8 changed files with 383 additions and 385 deletions.
11 changes: 0 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ hf-hub = "0.3.2"
tokenizers = "0.15"
thread-priority = "0.15"
regex = "1.5"
crossbeam-channel = "0.5"

[profile.dev.package."*"]
opt-level = 3
7 changes: 7 additions & 0 deletions migrations/20231120202003_queue.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
CREATE TABLE "queue" (
"id" integer NOT NULL PRIMARY KEY AUTOINCREMENT,
"text" text NOT NULL,
"channel" text NOT NULL,
"created_at" integer NOT NULL,
"leased_at" integer NOT NULL
);
15 changes: 2 additions & 13 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,7 @@
mod routes;
use sqlx::sqlite::SqlitePoolOptions;

pub async fn run(
database_url: String,
slack_oauth_token: String,
slack_signing_secret: String,
) -> Result<(), Box<dyn std::error::Error>> {
let db_pool = SqlitePoolOptions::new()
.max_connections(5)
.connect(database_url.as_str())
.await
.map_err(|e| format!("DB connection failed: {}", e))?;

let app = routes::create_routes(db_pool, slack_oauth_token, slack_signing_secret).await?;
pub async fn run() -> Result<(), Box<dyn std::error::Error>> {
let app = routes::create_routes().await?;
let bind_addr = &"0.0.0.0:51005"
.parse()
.map_err(|e| format!("Failed to parse address: {}", e))?;
Expand Down
8 changes: 1 addition & 7 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
use dotenvy::var;
use rust_slackbot_llm::run;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let slack_oauth_token = var("SLACK_OAUTH_TOKEN")
.map_err(|_| "Expected SLACK_OAUTH_TOKEN in the environment or .env file")?;
let slack_signing_secret = var("SLACK_SIGNING_SECRET")
.map_err(|_| "Expected SLACK_SIGNING_SECRET in the environment or .env file")?;
let database_url = var("DATABASE_URL").unwrap_or("sqlite://db/db.sqlite3".to_owned());
run(database_url, slack_oauth_token, slack_signing_secret).await
run().await
}
Loading

0 comments on commit 327116c

Please sign in to comment.