mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-08-24 08:01:38 +00:00
73deef44ed
This experimental crate demonstrates running Windmill preview endpoints
with libSQL (SQLite/Turso) instead of PostgreSQL. Key features:
- Schema: SQLite-compatible schema for jobs, queue, and results
- ENUMs → TEXT with CHECK constraints
- JSONB → JSON (TEXT)
- Arrays → JSON arrays
- No FOR UPDATE SKIP LOCKED (single worker, mutex coordination)
- Database: Supports three modes via libsql crate:
- In-memory SQLite (for testing)
- File-based SQLite (local persistence)
- Remote Turso (multi-writer scenarios)
- API: Compatible preview endpoints:
- POST /api/w/{workspace}/jobs/run/preview
- POST /api/w/{workspace}/jobs/run_wait_result/preview
- POST /api/w/{workspace}/jobs/run/preview_flow
- POST /api/w/{workspace}/jobs/run_wait_result/preview_flow
- Executor: Simple script execution for bash, python3, deno, bun
- Worker: Single embedded worker that processes queue
Run with: cargo run -p windmill-local --example local_server
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
66 lines
2.5 KiB
Rust
66 lines
2.5 KiB
Rust
//! Example: Run the Windmill local server
|
|
//!
|
|
//! This demonstrates running a local Windmill server with libSQL/SQLite backend.
|
|
//!
|
|
//! Run with:
|
|
//! cargo run -p windmill-local --example local_server
|
|
//!
|
|
//! Test with:
|
|
//! # Health check
|
|
//! curl http://localhost:8000/health
|
|
//!
|
|
//! # Run a bash preview (async)
|
|
//! curl -X POST http://localhost:8000/api/w/local/jobs/run/preview \
|
|
//! -H "Content-Type: application/json" \
|
|
//! -d '{"content": "echo Hello World", "language": "bash"}'
|
|
//!
|
|
//! # Run a bash preview and wait for result
|
|
//! curl -X POST http://localhost:8000/api/w/local/jobs/run_wait_result/preview \
|
|
//! -H "Content-Type: application/json" \
|
|
//! -d '{"content": "echo 42", "language": "bash"}'
|
|
//!
|
|
//! # Run a Python preview
|
|
//! curl -X POST http://localhost:8000/api/w/local/jobs/run_wait_result/preview \
|
|
//! -H "Content-Type: application/json" \
|
|
//! -d '{"content": "def main(x=1): return x * 2", "language": "python3", "args": {"x": 21}}'
|
|
//!
|
|
//! # Run a flow preview (linear flow with two steps)
|
|
//! curl -X POST http://localhost:8000/api/w/local/jobs/run_wait_result/preview_flow \
|
|
//! -H "Content-Type: application/json" \
|
|
//! -d '{
|
|
//! "value": {
|
|
//! "modules": [
|
|
//! {"id": "step1", "value": {"type": "rawscript", "language": "bash", "content": "echo 10"}},
|
|
//! {"id": "step2", "value": {"type": "identity"}}
|
|
//! ]
|
|
//! },
|
|
//! "args": {}
|
|
//! }'
|
|
|
|
use std::net::SocketAddr;
|
|
use windmill_local::LocalServer;
|
|
|
|
#[tokio::main]
|
|
async fn main() {
|
|
// Initialize tracing
|
|
tracing_subscriber::fmt()
|
|
.with_env_filter(
|
|
tracing_subscriber::EnvFilter::from_default_env()
|
|
.add_directive("windmill_local=info".parse().unwrap()),
|
|
)
|
|
.init();
|
|
|
|
let addr: SocketAddr = "0.0.0.0:8000".parse().unwrap();
|
|
println!("Starting Windmill Local Server on {}", addr);
|
|
println!();
|
|
println!("Test endpoints:");
|
|
println!(" Health: curl http://localhost:8000/health");
|
|
println!(" Preview: curl -X POST http://localhost:8000/api/w/local/jobs/run_wait_result/preview \\");
|
|
println!(" -H 'Content-Type: application/json' \\");
|
|
println!(" -d '{{\"content\": \"echo Hello\", \"language\": \"bash\"}}'");
|
|
println!();
|
|
|
|
let server = LocalServer::new(addr).await.expect("Failed to create server");
|
|
server.run().await.expect("Server error");
|
|
}
|