| Crates.io | jono |
| lib.rs | jono |
| version | 0.1.6-rc.8 |
| created_at | 2025-03-23 21:09:32.051119+00 |
| updated_at | 2025-04-22 05:25:35.903425+00 |
| description | Priority Queue on Redis |
| homepage | |
| repository | https://github.com/ruksi/jono-rs |
| max_upload_size | |
| id | 1603063 |
| size | 78,332 |
Jono is a priority queue based on Redis sorted sets and ULIDs.
These together allow for a priority queue where ZPOPMIN
is used to get the next job to be processed.
[dependencies]
jono = "0.1.6-rc.8"
# or, for minimal stuff:
jono = { version = "0.1.6-rc.8", default-features = false, features = ["produce", "runtime-tokio", "tls-none"] }
use jono::prelude::*;
use jono_core::Result;
use serde_json::json;
pub async fn codebase_1() -> Result<()> {
// tries "JONO_REDIS_URL" > "REDIS_URL" > Err
let context = Context::try_from_env("work-work")?;
// to submit new jobs:
let producer = Producer::with_context(context);
let job_id = JobPlan::new()
.payload(json!({"my-key": "my-value"}))
.submit(&producer)
.await?;
}
[dependencies]
jono = "0.1.6-rc.8"
# or, for minimal stuff:
jono = { version = "0.1.6-rc.8", default-features = false, features = ["consume", "runtime-tokio", "tls-none"] }
use jono::prelude::*;
use jono_core::Result;
pub async fn codebase_2() -> Result<()> {
// tries "JONO_REDIS_URL" > "REDIS_URL" > Err
let context = Context::try_from_env("work-work")?;
// to process jobs; the worker code is further below:
let consumer = Consumer::with_context(context, NoopWorker);
let summary = consumer.run_next().await?;
match summary {
Some(WorkSummary::Success(_)) => {
todo!("You want to do something on the worker right after?");
}
Some(WorkSummary::Failure(_)) => {
todo!("... or specifically on failure?");
}
None => {
todo!("... or do something if nothing was found in the queue?");
}
}
}
struct NoopWorker;
impl Worker for NoopWorker {
async fn work(&self, _: &Workload) -> Result<WorkSummary> {
Ok(WorkSummary::Success(Some(json!({"processed": true}))))
}
}
[dependencies]
jono = "0.1.6-rc.8"
# or, for minimal stuff:
jono = { version = "0.1.6-rc.8", default-features = false, features = ["harvest", "runtime-tokio", "tls-none"] }
use jono::prelude::*;
use jono_core::Result;
pub async fn codebase_3() -> Result<()> {
// tries "JONO_REDIS_URL" > "REDIS_URL" > Err
let context = Context::try_from_env("work-work")?;
// to post-process job results:
let harvester = Harvester::with_context(context);
let completed_jobs = harvester.harvest(3).await?;
// do something with the completed job result
// OR, use the `Reaper` trait approach, TODO
}