Skip to content

Commit 483e30e

Browse files
authored
chore: bump to beta (#16)
1 parent a785449 commit 483e30e

30 files changed

Lines changed: 722 additions & 777 deletions

.sqlx/query-61843a18bffdee192cd01f1537f0f03d75403970fc8347d0f017f04d746b2b98.json renamed to .sqlx/query-eed1a436f9bad0f9ee6c46b47580fa7bdc9acef7704fe86466d28fc85126b8e3.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1010

1111
### Added
1212

13+
- `apalis-board` support
1314
- Workflow support
15+
- Event driven listener
1416

1517
### Changed
1618

1719
- Moved from monorepo
20+
21+
22+
23+
Previous Document: https://github.com/apalis-dev/apalis/blob/main/CHANGELOG.md

Cargo.toml

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "apalis-sqlite"
3-
version = "1.0.0-alpha.6"
3+
version = "1.0.0-beta.1"
44
authors = ["Njuguna Mureithi <mureithinjuguna@gmail.com>"]
55
readme = "README.md"
66
edition = "2024"
@@ -11,7 +11,7 @@ keywords = ["apalis", "background-jobs", "task-queue", "sqlite", "async"]
1111
categories = ["asynchronous", "database"]
1212

1313
[features]
14-
default = ["migrate", "json"]
14+
default = ["tokio-comp", "migrate", "json"]
1515
migrate = ["sqlx/migrate", "sqlx/macros"]
1616
async-std-comp = ["async-std", "sqlx/runtime-async-std-rustls"]
1717
async-std-comp-native-tls = ["async-std", "sqlx/runtime-async-std-native-tls"]
@@ -27,28 +27,44 @@ features = ["chrono", "sqlite"]
2727
[dependencies]
2828
serde = { version = "1", features = ["derive"] }
2929
serde_json = { version = "1" }
30-
apalis-core = { version = "1.0.0-alpha.9", features = ["sleep"] }
31-
apalis-sql = { version = "1.0.0-alpha.9" }
30+
apalis-core = { version = "1.0.0-beta.1", features = ["sleep"] }
31+
apalis-sql = { version = "1.0.0-beta.1" }
3232
log = "0.4.21"
3333
futures = "0.3.30"
3434
tokio = { version = "1", features = ["rt", "net"], optional = true }
3535
async-std = { version = "1.13.0", optional = true }
3636
chrono = { version = "0.4", features = ["serde"] }
3737
thiserror = "2.0.0"
3838
pin-project = "1.1.10"
39-
libsqlite3-sys = "0.30.1"
4039
ulid = { version = "1", features = ["serde"] }
41-
bytes = "1.1.0"
4240

4341
[dev-dependencies]
4442
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
45-
apalis = { version = "1.0.0-alpha.9" }
46-
apalis-sqlite = { path = ".", features = ["migrate", "tokio-comp"] }
47-
apalis-workflow = { version = "0.1.0-alpha.6" }
48-
43+
apalis = { version = "1.0.0-beta.1" }
44+
apalis-workflow = { version = "0.1.0-beta.1" }
4945
futures-util = "0.3.31"
5046

5147
[package.metadata.docs.rs]
5248
# defines the configuration attribute `docsrs`
5349
rustdoc-args = ["--cfg", "docsrs"]
5450
all-features = true
51+
52+
[lints.rust]
53+
unsafe_code = "forbid"
54+
rust_2018_idioms = { level = "warn", priority = -1 }
55+
missing_debug_implementations = "warn"
56+
unreachable_pub = "warn"
57+
58+
[lints.clippy]
59+
type_complexity = "allow"
60+
manual_let_else = "warn"
61+
match_same_arms = "warn"
62+
match_wildcard_for_single_variants = "warn"
63+
mem_forget = "warn"
64+
must_use_candidate = "warn"
65+
needless_borrow = "warn"
66+
needless_continue = "warn"
67+
needless_pass_by_ref_mut = "warn"
68+
needless_pass_by_value = "warn"
69+
option_option = "warn"
70+
redundant_clone = "warn"

README.md

Lines changed: 85 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
# apalis-sqlite
22

3-
Background task processing for Rust using apalis and sqlite.
3+
Background task processing for Rust using `apalis` and `sqlite`.
44

55
## Features
66

77
- **Reliable job queue** using SQLite as the backend.
88
- **Multiple storage types**: standard polling and event-driven (hooked) storage.
99
- **Custom codecs** for serializing/deserializing job arguments as bytes.
1010
- **Heartbeat and orphaned job re-enqueueing** for robust job processing.
11-
- **Integration with Apalis workers and middleware.**
11+
- **Integration with `apalis` workers and middleware.**
1212

1313
## Storage Types
1414

@@ -23,11 +23,17 @@ The naming is designed to clearly indicate the storage mechanism and its capabil
2323
### Basic Worker Example
2424

2525
```rust,no_run
26+
use std::time::Duration;
27+
28+
use apalis::prelude::*;
29+
use apalis_sqlite::*;
30+
use futures::stream::{self, StreamExt};
31+
2632
#[tokio::main]
2733
async fn main() {
2834
let pool = SqlitePool::connect(":memory:").await.unwrap();
2935
SqliteStorage::setup(&pool).await.unwrap();
30-
let mut backend = SqliteStorage::new(&pool); // With default config
36+
let mut backend = SqliteStorage::new(&pool);
3137
3238
let mut start = 0;
3339
let mut items = stream::repeat_with(move || {
@@ -36,10 +42,10 @@ async fn main() {
3642
.run_after(Duration::from_secs(1))
3743
.with_ctx(SqlContext::new().with_priority(1))
3844
.build();
39-
Ok(task)
45+
task
4046
})
4147
.take(10);
42-
backend.send_all(&mut items).await.unwrap();
48+
backend.push_all(&mut items).await.unwrap();
4349
4450
async fn send_reminder(item: usize, wrk: WorkerContext) -> Result<(), BoxDynError> {
4551
Ok(())
@@ -55,19 +61,24 @@ async fn main() {
5561
### Hooked Worker Example (Event-driven)
5662

5763
```rust,no_run
64+
use std::time::Duration;
65+
66+
use apalis::prelude::*;
67+
use apalis_sqlite::*;
68+
use futures::stream::{self, StreamExt};
5869
5970
#[tokio::main]
6071
async fn main() {
61-
let pool = SqlitePool::connect(":memory:").await.unwrap();
62-
SqliteStorage::setup(&pool).await.unwrap();
63-
6472
let lazy_strategy = StrategyBuilder::new()
6573
.apply(IntervalStrategy::new(Duration::from_secs(5)))
6674
.build();
6775
let config = Config::new("queue")
6876
.with_poll_interval(lazy_strategy)
6977
.set_buffer_size(5);
70-
let backend = SqliteStorage::new_with_callback(&pool, &config).await;
78+
let backend = SqliteStorage::new_with_callback(":memory:", &config);
79+
80+
let pool = backend.pool();
81+
SqliteStorage::setup(&pool).await.unwrap();
7182
7283
tokio::spawn({
7384
let pool = pool.clone();
@@ -77,7 +88,7 @@ async fn main() {
7788
let mut start = 0;
7889
let items = stream::repeat_with(move || {
7990
start += 1;
80-
Task::builder(serde_json::to_value(&start).unwrap())
91+
Task::builder(serde_json::to_vec(&start).unwrap())
8192
.run_after(Duration::from_secs(1))
8293
.with_ctx(SqlContext::new().with_priority(start))
8394
.build()
@@ -103,32 +114,38 @@ async fn main() {
103114
### Workflow Example
104115

105116
```rust,no_run
117+
use std::time::Duration;
118+
119+
use apalis::prelude::*;
120+
use apalis_sqlite::*;
121+
use apalis_workflow::*;
122+
106123
#[tokio::main]
107124
async fn main() {
108125
let workflow = Workflow::new("odd-numbers-workflow")
109-
.then(|a: usize| async move {
110-
Ok::<_, WorkflowError>((0..=a).collect::<Vec<_>>())
126+
.and_then(|a: usize| async move {
127+
Ok::<Vec<usize>, BoxDynError>((0..=a).collect::<Vec<usize>>())
111128
})
112-
.filter_map(|x| async move {
129+
.filter_map(|x: usize| async move {
113130
if x % 2 != 0 { Some(x) } else { None }
114131
})
115-
.filter_map(|x| async move {
132+
.filter_map(|x: usize| async move {
116133
if x % 3 != 0 { Some(x) } else { None }
117134
})
118-
.filter_map(|x| async move {
135+
.filter_map(|x: usize| async move {
119136
if x % 5 != 0 { Some(x) } else { None }
120137
})
121138
.delay_for(Duration::from_millis(1000))
122-
.then(|a: Vec<usize>| async move {
139+
.and_then(|a: Vec<usize>| async move {
123140
println!("Sum: {}", a.iter().sum::<usize>());
124-
Ok::<(), WorkflowError>(())
141+
Ok::<(), BoxDynError>(())
125142
});
126143
127144
let pool = SqlitePool::connect(":memory:").await.unwrap();
128145
SqliteStorage::setup(&pool).await.unwrap();
129146
let mut sqlite = SqliteStorage::new_in_queue(&pool, "test-workflow");
130147
131-
sqlite.push(100usize).await.unwrap();
148+
sqlite.push_start(100usize).await.unwrap();
132149
133150
let worker = WorkerBuilder::new("rango-tango")
134151
.backend(sqlite)
@@ -144,6 +161,56 @@ async fn main() {
144161
}
145162
```
146163

164+
### Shared Example
165+
166+
Full support for sharing the same connection. This example shows how to run multiple types with one function
167+
168+
```rust,no_run
169+
use std::{collections::HashMap, time::Duration};
170+
171+
use apalis::prelude::*;
172+
use apalis_sqlite::{SharedSqliteStorage, SqliteStorage};
173+
174+
use futures::stream;
175+
176+
#[tokio::main]
177+
async fn main() {
178+
179+
let mut store = SharedSqliteStorage::new(":memory:");
180+
181+
SqliteStorage::setup(store.pool()).await.unwrap();
182+
183+
let mut map_store = store.make_shared().unwrap();
184+
185+
let mut int_store = store.make_shared().unwrap();
186+
187+
map_store
188+
.push_stream(&mut stream::iter(vec![HashMap::<String, String>::new()]))
189+
.await
190+
.unwrap();
191+
int_store.push(99).await.unwrap();
192+
193+
async fn send_reminder<T, I>(
194+
_: T,
195+
_task_id: TaskId<I>,
196+
wrk: WorkerContext,
197+
) -> Result<(), BoxDynError> {
198+
tokio::time::sleep(Duration::from_secs(2)).await;
199+
wrk.stop().unwrap();
200+
println!("Reminder sent!");
201+
Ok(())
202+
}
203+
204+
let int_worker = WorkerBuilder::new("rango-tango-2")
205+
.backend(int_store)
206+
.build(send_reminder);
207+
let map_worker = WorkerBuilder::new("rango-tango-1")
208+
.backend(map_store)
209+
.build(send_reminder);
210+
tokio::try_join!(int_worker.run(), map_worker.run()).unwrap();
211+
}
212+
```
213+
147214
## Observability
148215

149216
You can track your jobs using [apalis-board](https://github.com/apalis-dev/apalis-board).

build.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
//! build.rs
2+
//! Build script to handle database migrations for apalis-sqlite.
13
fn main() {
24
println!("cargo:rerun-if-changed=migrations");
35
}

examples/basic.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use apalis::prelude::*;
2+
use apalis_sqlite::SqliteStorage;
3+
use sqlx::SqlitePool;
4+
5+
#[tokio::main]
6+
async fn main() {
7+
let pool = SqlitePool::connect(":memory:").await.unwrap();
8+
SqliteStorage::setup(&pool).await.unwrap();
9+
let mut backend = SqliteStorage::new(&pool);
10+
backend.push(42).await.unwrap();
11+
12+
async fn task(task: u32, worker: WorkerContext) -> Result<(), BoxDynError> {
13+
apalis_core::timer::sleep(std::time::Duration::from_secs(1)).await;
14+
assert_eq!(task, 42);
15+
worker.stop()?;
16+
Ok(())
17+
}
18+
let worker = WorkerBuilder::new("rango-tango")
19+
.backend(backend)
20+
.build(task);
21+
worker.run().await.unwrap();
22+
}

examples/realtime.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
use apalis::prelude::*;
2+
use apalis_sqlite::{Config, SqliteStorage};
3+
4+
#[tokio::main]
5+
async fn main() {
6+
let config = Config::new("realtime-queue");
7+
let mut backend = SqliteStorage::new_with_callback(":memory:", &config);
8+
9+
let pool = backend.pool();
10+
SqliteStorage::setup(&pool).await.unwrap();
11+
12+
backend.push(42).await.unwrap();
13+
14+
async fn task(task: u32, worker: WorkerContext) -> Result<(), BoxDynError> {
15+
apalis_core::timer::sleep(std::time::Duration::from_secs(1)).await;
16+
assert_eq!(task, 42);
17+
worker.stop()?;
18+
Ok(())
19+
}
20+
let worker = WorkerBuilder::new("rango-tango")
21+
.backend(backend)
22+
.build(task);
23+
worker.run().await.unwrap();
24+
}

examples/shared.rs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
use std::{collections::HashMap, time::Duration};
2+
3+
use apalis::prelude::*;
4+
use apalis_sqlite::{SharedSqliteStorage, SqliteStorage};
5+
6+
use futures::stream;
7+
8+
#[tokio::main]
9+
async fn main() {
10+
let mut store = SharedSqliteStorage::new(":memory:");
11+
12+
SqliteStorage::setup(store.pool()).await.unwrap();
13+
14+
let mut map_store = store.make_shared().unwrap();
15+
16+
let mut int_store = store.make_shared().unwrap();
17+
18+
map_store
19+
.push_stream(&mut stream::iter(vec![HashMap::<String, String>::new()]))
20+
.await
21+
.unwrap();
22+
int_store.push(99).await.unwrap();
23+
24+
async fn send_reminder<T, I>(
25+
_: T,
26+
_task_id: TaskId<I>,
27+
wrk: WorkerContext,
28+
) -> Result<(), BoxDynError> {
29+
tokio::time::sleep(Duration::from_secs(2)).await;
30+
wrk.stop().unwrap();
31+
println!("Reminder sent!");
32+
Ok(())
33+
}
34+
35+
let int_worker = WorkerBuilder::new("rango-tango-2")
36+
.backend(int_store)
37+
.build(send_reminder);
38+
let map_worker = WorkerBuilder::new("rango-tango-1")
39+
.backend(map_store)
40+
.build(send_reminder);
41+
tokio::try_join!(int_worker.run(), map_worker.run()).unwrap();
42+
}

examples/with_ui.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fn main() {}

0 commit comments

Comments
 (0)