-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.rs
83 lines (72 loc) · 2.24 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
extern crate flate2;
use std::error::Error;
use std::time;
use std::io::prelude::*;
use beanstalkc::Beanstalkc;
use flate2::Compression;
use flate2::write::GzEncoder;
use flate2::read::GzDecoder;
fn main() -> Result<(), Box<dyn Error>> {
let mut conn = Beanstalkc::new()
.host("localhost")
.port(11300)
.connection_timeout(Some(time::Duration::from_secs(1)))
.connect()
.expect("connection failed");
dbg!(conn.put_default(b"hello"))?;
dbg!(conn.put(
b"Hello, rust world.",
0,
time::Duration::from_secs(100),
time::Duration::from_secs(1800)
))?;
dbg!(conn.reserve())?;
dbg!(conn.kick(100))?;
dbg!(conn.kick_job(10))?;
dbg!(conn.peek(10))?;
dbg!(conn.peek_ready())?;
dbg!(conn.peek_buried())?;
dbg!(conn.peek_delayed())?;
dbg!(conn.tubes())?;
dbg!(conn.using())?;
dbg!(conn.use_tube("jobs"))?;
dbg!(conn.watch("jobs"))?;
dbg!(conn.watching())?;
dbg!(conn.ignore("jobs"))?;
dbg!(conn.ignore("default"))?;
dbg!(conn.stats_tube("default"))?;
dbg!(conn.pause_tube("jobs", time::Duration::from_secs(10)))?;
dbg!(conn.pause_tube("not-found", time::Duration::from_secs(10)))?;
let mut job = conn.reserve()?;
dbg!(job.id());
dbg!(std::str::from_utf8(job.body()))?;
dbg!(job.reserved());
dbg!(job.bury_default())?;
dbg!(job.kick())?;
dbg!(job.touch())?;
dbg!(job.stats())?;
dbg!(job.touch())?;
dbg!(job.release_default())?;
dbg!(job.delete())?;
let mut job = conn.reserve()?;
dbg!(job.delete())?;
// should also work with potentially non-UTF-8 payloads
// puts a gzip encoded message
let mut e = GzEncoder::new(Vec::new(), Compression::default());
e.write_all(b"Hello beanstalkc compressed")?;
let buf = e.finish()?;
dbg!(conn.put_default(&buf))?;
// tries to read the gzipped encoded message back to a string
let mut job = conn.reserve()?;
let mut buf = &job.body().to_owned()[..];
let mut gz = GzDecoder::new(&mut buf);
let mut s = String::new();
gz.read_to_string(&mut s)?;
dbg!(s);
job.delete()?;
let mut conn = conn.reconnect()?;
dbg!(conn.stats())?;
let stats = conn.stats()?;
dbg!(stats);
Ok(())
}