-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
117 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[env] | ||
RUNTIME_SNAPSHOT_PATH = { value = "/tmp/openworkers-runtime-snapshot.bin", relative = false } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.vscode | ||
.git | ||
|
||
target | ||
|
||
.env |
22 changes: 22 additions & 0 deletions
22
.sqlx/query-83b9ee13ebbd0e75fe09075eef2c41296626244dbefb2f411638e44ae46ac2e0.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
{ | ||
"cSpell.words": ["actix", "nats", "oneshot", "sqlx"] | ||
"cSpell.words": ["actix", "dotenv", "nats", "oneshot", "sqlx"] | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
FROM rust:1.77 as builder | ||
|
||
RUN mkdir -p /build/openworkers-runner | ||
|
||
ENV RUST_BACKTRACE=1 | ||
ENV RUNTIME_SNAPSHOT_PATH=/build/snapshot.bin | ||
|
||
WORKDIR /build/openworkers-runner | ||
|
||
COPY . /build/openworkers-runner | ||
|
||
RUN touch $RUNTIME_SNAPSHOT_PATH | ||
|
||
RUN --mount=type=cache,target=~/.cargo \ | ||
--mount=type=cache,target=/build/openworkers-runner/target \ | ||
cargo run --release --bin snapshot && \ | ||
cargo build --release && cp /build/openworkers-runner/target/release/openworkers-runner /build/output | ||
|
||
FROM debian:bookworm-slim | ||
|
||
COPY --from=builder /build/output /usr/local/bin/openworkers-runner | ||
|
||
CMD ["/usr/local/bin/openworkers-runner"] | ||
|
||
EXPOSE 8080 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -179,6 +179,8 @@ async fn handle_request(data: Data<AppState>, req: HttpRequest) -> HttpResponse | |
|
||
#[actix_web::main] | ||
async fn main() -> std::io::Result<()> { | ||
dotenv::dotenv().ok(); | ||
|
||
if !std::env::var("RUST_LOG").is_ok() { | ||
std::env::set_var("RUST_LOG", "info"); | ||
} | ||
|
@@ -187,8 +189,7 @@ async fn main() -> std::io::Result<()> { | |
|
||
debug!("start main"); | ||
|
||
let db_url = std::env::var("DATABASE_URL") | ||
.unwrap_or("postgres://admin:[email protected]/swap_dev".to_string()); | ||
let db_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set"); | ||
let pool = PgPoolOptions::new() | ||
.max_connections(4) | ||
.connect(&db_url) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
pub mod scheduled; | ||
pub mod store; | ||
pub mod log; | ||
pub mod nats; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
use base64::{engine::general_purpose::STANDARD, Engine as _}; | ||
|
||
pub fn nats_connect() -> nats::Connection { | ||
let nats_servers = std::env::var("NATS_SERVERS").expect("NATS_SERVERS must be set"); | ||
|
||
log::debug!("connecting to nats: {nats_servers}"); | ||
|
||
let conn = match std::env::var("NATS_CREDS") { | ||
Ok(credentials) => { | ||
// Decode the base64 encoded credentials | ||
let credentials: Vec<u8> = STANDARD.decode(credentials).expect("failed to decode credentials"); | ||
let credentials = String::from_utf8(credentials).expect("failed to convert credentials to string"); | ||
let options = nats::Options::with_static_credentials(&credentials).expect("failed to create nats options"); | ||
|
||
options.connect(nats_servers) | ||
}, | ||
Err(_) => nats::connect(nats_servers), | ||
}; | ||
|
||
conn.expect("failed to connect to nats") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters