Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/neurophant/rjq
Redis Job Queue
https://github.com/neurophant/rjq
Last synced: about 18 hours ago
JSON representation
Redis Job Queue
- Host: GitHub
- URL: https://github.com/neurophant/rjq
- Owner: neurophant
- License: mit
- Created: 2017-01-28T12:33:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-08-12T09:50:28.000Z (over 7 years ago)
- Last Synced: 2024-10-29T00:39:49.263Z (16 days ago)
- Language: Rust
- Size: 16.6 KB
- Stars: 16
- Watchers: 1
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# Redis Job Queue
Simple redis job queue
[![crates.io](https://img.shields.io/crates/v/rjq.svg)](https://crates.io/crates/rjq)
[![Build Status](https://travis-ci.org/embali/rjq.svg?branch=master)](https://travis-ci.org/embali/rjq)## Documentation
https://docs.rs/rjq/
## Enqueue jobs
```rust
extern crate rjq;use std::time::Duration;
use std::thread::sleep;
use rjq::Queue;fn main() {
let queue = Queue::new("redis://localhost/", "rjq");
let mut uuids = Vec::new();for _ in 0..10 {
sleep(Duration::from_millis(100));
uuids.push(queue.enqueue(vec![], 30).unwrap());
}sleep(Duration::from_millis(10000));
for uuid in uuids.iter() {
let status = queue.status(uuid).unwrap();
let result = queue.result(uuid).unwrap().unwrap();
println!("{} {:?} {}", uuid, status, result);
}
}
```## Queue worker
```rust
extern crate rjq;use std::time::Duration;
use std::thread::sleep;
use std::error::Error;
use rjq::Queue;fn main() {
fn process(uuid: String, _: Vec) -> Result> {
sleep(Duration::from_millis(1000));
println!("{}", uuid);
Ok(format!("hi from {}", uuid))
}let queue = Queue::new("redis://localhost/", "rjq");
queue.work(process, Some(1), Some(5), Some(10), Some(30), Some(false), None).unwrap();
}
```## Job status
**QUEUED** - job queued for further processing
**RUNNING** - job is running by worker
**LOST** - job has not been finished in time
**FINISHED** - job has been successfully finished
**FAILED** - job has been failed due to some errors
## Queue methods
### Init queue
```rust
fn new(url: &str, name: &str) -> Queue;
```**url** - redis URL
**name** - queue name
Returns **queue**
### Drop queue jobs
```rust
fn drop(&self) -> Result<(), Box>;
```### Enqueue job
```rust
fn enqueue(&self, args: Vec, expire: usize) -> Result>;
```**args** - job arguments
**expire** - if job has not been started by worker in this time (in seconds), it will expire
Returns job **UUID**
### Get job status
```rust
fn status(&self, uuid: &str) -> Result>;
```**uuid** - job unique identifier
Returns job **status**
### Work on queue
```rust
fn work) -> Result> + Send + Sync + 'static>
(&self,
fun: F,
wait: Option,
timeout: Option,
freq: Option,
expire: Option,
fall: Option,
infinite: Option)
-> Result<(), Box>;
```**fun** - worker function
**wait** - time to wait until next job will pop
**timeout** - worker function should finish in timeout (in seconds)
**freq** - job status check frequency (times per second)
**expire** - job result will expire in this time (in seconds)
**fall** - panics to terminate process if the job has been lost
**infinite** - process jobs infinitely one after another, otherwise only one job will be processed
### Get job result
```rust
fn result(&self, uuid: &str) -> Result, Box>;
```**uuid** - job unique identifier
Returns job **result**
## Run tests
```bash
cargo test
```