Overview
Comment: | update regexp to include uppercase letters |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | master | trunk |
Files: | files | file ages | folders |
SHA3-256: |
f721596292856c2d47a6a81140edb04f |
User & Date: | arcade on 2018-10-28 13:32:16.302 |
Other Links: | branch diff | manifest | tags |
Context
2018-10-28
| ||
13:32 | update regexp to include uppercase letters Leaf check-in: f721596292 user: arcade tags: master, trunk | |
2018-06-01
| ||
10:35 | update script, multiple schemas, rust offloader check-in: b33171b487 user: arcade@b1t.name tags: master, trunk | |
Changes
Modified offload/src/main.rs
from [1e0198fa61]
to [f70755a4b3].
︙ | ︙ | |||
14 15 16 17 18 19 20 | loop { let mut settings = config::Config::default(); settings.merge(config::File::with_name("offload")).expect("Can't read configuration file"); let reddb = redis::Client::open("redis://127.0.0.1/").expect("Can't connect to the database"); let red = reddb.get_connection().expect("Can't initialize new connection"); | | | 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | loop { let mut settings = config::Config::default(); settings.merge(config::File::with_name("offload")).expect("Can't read configuration file"); let reddb = redis::Client::open("redis://127.0.0.1/").expect("Can't connect to the database"); let red = reddb.get_connection().expect("Can't initialize new connection"); let re = Regex::new("^([0-9A-Z]+)[|_]([a-zA-Z./0-9-_#]+)[|_]([0-9.]+)$").expect("Can't parse regexp"); let conn = Connection::connect(settings.get_str("pg").expect("Postgres connection absent in config"), TlsMode::None).expect("Can't connect to postgres"); let schemas = settings.get_array("schemas").expect("Schema list not found in config").into_iter().map(|value| config::Value::into_str(value).expect("We require string here")); for schema in schemas { let data_key = schema.to_owned() + "_counter_pending"; let cache_key = schema.to_owned() + "_counter_pending_now"; |
︙ | ︙ | |||
37 38 39 40 41 42 43 | //println!("# {:?}", stats); let trans = conn.transaction().expect("Can't start transaction"); let stmt = trans.prepare(&format!("select {}.merge_counter($1::text, $2::text, ($3::text)::inet, $4::smallint);", &schema)).expect("Can't prepare statement"); for (client, count) in stats { //println!("# {:?}: {:?}", &client, &count); | | | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | //println!("# {:?}", stats); let trans = conn.transaction().expect("Can't start transaction"); let stmt = trans.prepare(&format!("select {}.merge_counter($1::text, $2::text, ($3::text)::inet, $4::smallint);", &schema)).expect("Can't prepare statement"); for (client, count) in stats { //println!("# {:?}: {:?}", &client, &count); let cap = re.captures(&client).expect(&format!("Client match failed: {}", &client)); //let addr = IpAddr::V4(cap[3].parse().expect("Can't parse IP")); //println!("insert into x values({:?}, {:?}, {:?}, {:?});", &cap[1], &cap[2], &cap[3], &count); stmt.execute(&[&cap[1].to_string(), &cap[2].to_string(), &cap[3].to_string(), &count]).expect("Can't execute prepared"); //trans.query(&format!("select {}.merge_counter($1::text, $2::text, $3::inet, $4::smallint);", &schema), &[&cap[1].to_string(), &cap[2].to_string(), &cap[3].to_string(), &count]).expect("Can't prepare statement"); } trans.commit().expect("Can't commit transaction"); red.del(cache_key).expect("Can't remove stale key") } thread::sleep(Duration::new(settings.get("delay").expect("Delay specification absent in config"), 0)); } } |