Skip to content
This repository has been archived by the owner on Oct 3, 2024. It is now read-only.

Commit

Permalink
Service setup changes; Prefixes for env var names
Browse files Browse the repository at this point in the history
  • Loading branch information
automainint committed Jun 5, 2024
1 parent 0a71841 commit 2f768c2
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 31 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
sudo apt-get install -y postgresql-16 postgresql-server-dev-16
- name: Prepare env
run: |
sudo su - root -c "echo \"export RUST_SERVICE_URL=tcp://127.0.0.1:10444\" >> /etc/environment"
sudo su - root -c "echo \"export MERITRANK_SERVICE_URL=tcp://127.0.0.1:10444\" >> /etc/environment"
- name: Build the connector
run: |
cargo install --locked cargo-pgrx
Expand All @@ -31,9 +31,8 @@ jobs:
git clone --branch dev --depth 1 https://github.com/Intersubjective/meritrank-service-rust.git
cd meritrank-service-rust
cargo build --release
export RUST_SERVICE_URL=tcp://127.0.0.1:10444
export NUM_WALK=500
export GRAVITY_NUM_WALK=500
export MERITRANK_SERVICE_URL=tcp://127.0.0.1:10444
export MERITRANK_NUM_WALK=500
cargo run --release >/dev/null 2>&1 &
- name: Do the tests
run: |
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "pgmer2"
version = "0.3.2"
version = "0.3.3"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
# meritrank-psql-connector (pgmer2)

MeritRank pgrx NNG connector.

The extention module is still calling **pgmer2**!

See also:
1. Server sample: https://github.com/shestero/pgmer2serv .
2. HTTP API analogue: https://github.com/shestero/pgmer1 .
1. Server sample: https://github.com/shestero/pgmer2serv
2. HTTP API analogue: https://github.com/shestero/pgmer1

## Dev setup for manual testing
## Env variables
- `MERITRANK_SERVICE_URL` - default `tcp://127.0.0.1:10234`
- `MERITRANK_RECV_TIMEOUT_MSEC` - default `10000` (10 seconds)

## Dev setup for manual testing
- Set RUST_SERVICE_URL value

```sh
export RUST_SERVICE_URL=tcp://127.0.0.1:10444
export MERITRANK_SERVICE_URL=tcp://127.0.0.1:10444
```

- Checkout and run `meritrank-service-rust`
Expand Down
1 change: 1 addition & 0 deletions sql/pgmer2--0.3.1--0.3.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE FUNCTION "mr_zerorec"() RETURNS TEXT STRICT LANGUAGE c AS 'MODULE_PATHNAME', 'mr_zerorec_wrapper';
1 change: 1 addition & 0 deletions sql/pgmer2--0.3.2--0.3.3.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

43 changes: 22 additions & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ pub mod testing;
pg_module_magic!();

lazy_static! {
static ref SERVICE_URL: String =
var("RUST_SERVICE_URL").unwrap_or("tcp://127.0.0.1:10234".to_string());
}
static ref SERVICE_URL : String =
var("MERITRANK_SERVICE_URL").unwrap_or("tcp://127.0.0.1:10234".to_string());

const VERSION: Option<&str> = option_env!("CARGO_PKG_VERSION");
static ref RECV_TIMEOUT_MSEC : u64 =
var("MERITRANK_RECV_TIMEOUT_MSEC").unwrap_or(10000);
}

const RECV_TIMEOUT_MSEC : u64 = 10000;
const VERSION : Option<&str> = option_env!("CARGO_PKG_VERSION");

fn request_raw(payload : Vec<u8>, timeout_msec : Option<u64>) -> Result<Message, Box<dyn Error + 'static>> {
let client = Socket::new(Protocol::Req0)?;
Expand Down Expand Up @@ -76,7 +77,7 @@ fn mr_connector() -> &'static str { &VERSION.unwrap_or("unknown") }

fn mr_service_wrapped() -> Result<String, Box<dyn Error + 'static>> {
let payload = rmp_serde::to_vec(&"ver")?;
let response = request_raw(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request_raw(payload, Some(*RECV_TIMEOUT_MSEC))?;
let s = rmp_serde::from_slice(response.as_slice())?;
return Ok(s);
}
Expand All @@ -100,7 +101,7 @@ fn mr_node_score_superposition(
Box<dyn Error + 'static>,
> {
let payload = rmp_serde::to_vec(&((("src", "=", ego), ("dest", "=", target)), ()))?;
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand All @@ -115,7 +116,7 @@ fn mr_node_score(
> {
let payload = rmp_serde::to_vec(&((("src", "=", ego), ("dest", "=", target)), ()))?;
let payload = if context.is_empty() { payload } else { contexted_payload(context, payload)? };
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand All @@ -128,7 +129,7 @@ fn mr_node_score_linear_sum(
Box<dyn Error + 'static>,
> {
let payload = rmp_serde::to_vec(&((("src", "=", ego), ("dest", "=", target)), (), "null"))?;
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand Down Expand Up @@ -193,7 +194,7 @@ fn mr_scores_superposition(
score_gt, score_gte,
limit
)?;
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand Down Expand Up @@ -221,7 +222,7 @@ fn mr_scores(
limit
)?;
let payload = if context.is_empty() { payload } else { contexted_payload(context, payload)? };
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand All @@ -233,7 +234,7 @@ fn mr_scores_linear_sum(
Box<dyn Error + 'static>,
> {
let payload = rmp_serde::to_vec(&((("src", "=", src), ), (), "null"))?;
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand All @@ -246,7 +247,7 @@ fn mr_score_linear_sum(
Box<dyn Error + 'static>,
> {
let payload = rmp_serde::to_vec(&((("src", "=", src), ("dest", "=", dest)), (), "null"))?;
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand All @@ -264,7 +265,7 @@ fn mr_put_edge(
> {
let payload = rmp_serde::to_vec(&(((src, dest, weight), ), ()))?;
let payload = if context.is_empty() { payload } else { contexted_payload(context, payload)? };
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand All @@ -276,7 +277,7 @@ fn mr_delete_edge(
) -> Result<&'static str, Box<dyn Error + 'static>> {
let payload = rmp_serde::to_vec(&((("src", "delete", ego), ("dest", "delete", target)), ()))?;
let payload = if context.is_empty() { payload } else { contexted_payload(context, payload)? };
let _ : Vec<()> = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let _ : Vec<()> = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok("Ok");
}

Expand All @@ -287,7 +288,7 @@ fn mr_delete_node(
) -> Result<&'static str, Box<dyn Error + 'static>> {
let payload = rmp_serde::to_vec(&((("src", "delete", ego), ), ()))?;
let payload = if context.is_empty() { payload } else { contexted_payload(context, payload)? };
let _ : Vec<()> = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let _ : Vec<()> = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok("Ok");
}

Expand All @@ -306,7 +307,7 @@ fn mr_graph(
> {
let payload = rmp_serde::to_vec(&(((ego, "gravity", focus), positive_only, limit), ()))?;
let payload = if context.is_empty() { payload } else { contexted_payload(context, payload)? };
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand All @@ -323,7 +324,7 @@ fn mr_nodes(
> {
let payload = rmp_serde::to_vec(&(((ego, "gravity_nodes", focus), positive_only, limit), ()))?;
let payload = if context.is_empty() { payload } else { contexted_payload(context, payload)? };
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand All @@ -348,7 +349,7 @@ fn mr_nodelist(context: &str) -> Result<
> {
let payload = rmp_serde::to_vec(&("nodes", ()))?;
let payload = if context.is_empty() { payload } else { contexted_payload(context, payload)? };
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand All @@ -361,7 +362,7 @@ fn mr_edgelist(
> {
let payload = rmp_serde::to_vec(&("edges", ()))?;
let payload = if context.is_empty() { payload } else { contexted_payload(context, payload)? };
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand All @@ -377,7 +378,7 @@ fn mr_connected(
> {
let payload = rmp_serde::to_vec(&(((ego, "connected"), ), ()))?;
let payload = if context.is_empty() { payload } else { contexted_payload(context, payload)? };
let response = request(payload, Some(RECV_TIMEOUT_MSEC))?;
let response = request(payload, Some(*RECV_TIMEOUT_MSEC))?;
return Ok(TableIterator::new(response));
}

Expand Down

0 comments on commit 2f768c2

Please sign in to comment.