Skip to content

Commit

Permalink
chore: create watcher and api builders (#358)
Browse files Browse the repository at this point in the history
  • Loading branch information
tipogi authored Mar 5, 2025
1 parent dbfa50b commit 053cb90
Show file tree
Hide file tree
Showing 67 changed files with 1,250 additions and 590 deletions.
34 changes: 17 additions & 17 deletions .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -4,46 +4,46 @@ RUST_LOG=info
# OTLP_ENDPOINT is set to empty by default. If you want to enable tracing, set it to the OpenTelemetry Collector endpoint
# OTLP_ENDPOINT=http://localhost:4317
OTLP_ENDPOINT=
# Service name for tracing. nexus.service, nexus.watcher, nexus.benchmarks, nexus.migrations, nexus.test, etc
OTEL_SERVICE_NAME=nexus.service

# Reindex on start up. Will create all Redis index keys from the Neo4J graph
REINDEX=false

# Service
SERVER_HOST=localhost
SERVER_PORT=8080

# Watcher
TESTNET=true
# Testnet bootstrap IP:PORT
BOOTSTRAP=127.0.0.1:6881
# Homeserver ID. Needed for event streams.
HOMESERVER=
HOMESERVER=8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo
# Maximum number of events to fetch at once from a homeserver
EVENTS_LIMIT=1000
# Sleep between checks to homeserver
WATCHER_SLEEP=5000
# Max amount of event retries
MAX_RETRIES=1

# Directory where static files are stored
STATIC_PATH=./static

FILE_PATH=./static/files
BASE_FILE_URL=localhost:8080/static/files/

# Neo4j database
NEO4J_HOST=localhost
NEO4J_PORT=7687
# Neo4J community does not support custom db_name and db_username, the default ones are 'neo4j'
NEO4J_DB_NAME=neo4j
NEO4J_DB_USERNAME=neo4j
NEO4J_PASSWORD=12345678

# Redis database
REDIS_HOST=localhost
REDIS_PORT=6379

# Migrations
MIGRATIONS_BACKFILL_READY=CommaSeparated,MigrationNames
MIGRATIONS_BACKFILL_READY=CommaSeparated,MigrationNames


# Max amount of event retries
#MAX_RETRIES=1
# Testnet bootstrap IP:PORT
#BOOTSTRAP=127.0.0.1:6881
# Reindex on start up. Will create all Redis index keys from the Neo4J graph
#REINDEX=false
# Neo4J community does not support custom db_name and db_username, the default ones are 'neo4j'
#NEO4J_DB_NAME=neo4j
#NEO4J_DB_USERNAME=neo4j
#STATIC_PATH=./static
#BASE_FILE_URL=localhost:8080/static/files/
# Service name for tracing. nexus.service, nexus.watcher, nexus.benchmarks, nexus.migrations, nexus.test, etc
#OTEL_SERVICE_NAME=nexus.service
5 changes: 4 additions & 1 deletion .github/workflows/format.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ on:
workflow_dispatch:
workflow_call:
push:
branches: ["main"]
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
format:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ on:
workflow_dispatch:
workflow_call:
push:
branches: ["main"]
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
lint:
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ on:
workflow_dispatch:
workflow_call:
push:
branches: ["main"]
branches:
- main
- dev
pull_request:
branches:
- main
- dev

jobs:
test:
Expand Down Expand Up @@ -66,7 +69,7 @@ jobs:
run: sudo apt install -y imagemagick

- name: Load Mock Data
run: cargo run --bin mockdb
run: cargo run -- db mock

- name: Run integration tests
run: cargo nextest run --no-fail-fast
Expand Down
2 changes: 2 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

64 changes: 33 additions & 31 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,38 @@ description = "Nexus between homeservers and Pubky-App. Pubky-nexus constructs a
homepage = "https://github.com/pubky"
repository = "https://github.com/pubky/pubky-nexus"
license = "MIT"
default-run = "service"
#default-run = "service"
build = "build.rs"

[dependencies]
pubky = "0.4.1"
pubky-testnet = "0.1.1"
pubky-app-specs = { version = "0.3.2", features = ["openapi"] }
tokio = { version = "1.43.0", features = ["full"] }
async-trait = "0.1.85"
axum = "0.8.1"
redis = { version = "0.29.0", features = ["tokio-comp", "json"] }
chrono = { version = "0.4.39", default-features = false, features = ["clock"] }
clap = { version = "4.5.29", features = ["derive"] }
const_format = "0.2.34"
dotenv = "0.15"
neo4rs = "0.8.0"
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.137"
once_cell = "1.20.2"
utoipa = "5.3.1"
utoipa-swagger-ui = { version = "9.0.0", features = ["axum"] }
tower-http = { version = "0.6.2", features = ["fs", "cors"] }
dotenv = "0.15"
tracing = "0.1"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
tracing-opentelemetry = "0.29"
opentelemetry = { version = "0.28" }
opentelemetry-appender-tracing = "0.28.1"
opentelemetry-otlp = { version = "0.28", features = ["grpc-tonic"] }
opentelemetry-stdout = { version = "0.28" }
opentelemetry_sdk = { version = "0.28", features = ["rt-tokio"] }
opentelemetry-appender-tracing = "0.28.1"
const_format = "0.2.34"
pubky = "0.4.1"
pubky-app-specs = { version = "0.3.2", features = ["openapi"] }
pubky-testnet = "0.1.1"
redis = { version = "0.29.0", features = ["tokio-comp", "json"] }
serde = { version = "1.0.217", features = ["derive"] }
serde_json = "1.0.137"
thiserror = "2.0.11"
chrono = { version = "0.4.39", default-features = false, features = ["clock"] }
async-trait = "0.1.85"
tokio = { version = "1.43.0", features = ["full"] }
toml = "0.8.20"
tower-http = { version = "0.6.2", features = ["fs", "cors"] }
tracing = "0.1"
tracing-opentelemetry = "0.29"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
utoipa = "5.3.1"
utoipa-swagger-ui = { version = "9.0.0", features = ["axum"] }

[dev-dependencies]
anyhow = "1.0.95"
Expand All @@ -52,21 +54,21 @@ reqwest = "0.12.12"
name = "pubky_nexus"
path = "src/lib.rs"

[[bin]]
name = "service"
path = "src/service.rs"
# [[bin]]
# name = "service"
# path = "src/service.rs"

[[bin]]
name = "watcher"
path = "src/watcher.rs"
# [[bin]]
# name = "watcher"
# path = "src/watcher.rs"

[[bin]]
name = "migrations"
path = "src/migrations.rs"
# [[bin]]
# name = "migrations"
# path = "src/migrations.rs"

[[bin]]
name = "mockdb"
path = "src/mock_db.rs"
# [[bin]]
# name = "mockdb"
# path = "src/mock_db.rs"

[[bench]]
name = "user"
Expand Down
5 changes: 2 additions & 3 deletions benches/setup.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use pubky_nexus::{Config, StackManager};
use pubky_nexus::_service::NexusApi;
use std::{env, sync::Once};
use tokio::runtime::Runtime;

Expand All @@ -9,8 +9,7 @@ pub fn run_setup() {
let rt = Runtime::new().unwrap();
env::set_var("RUST_LOG", "error");
rt.block_on(async {
let config = Config::from_env();
StackManager::setup(&config).await;
NexusApi::builder().init_stack().await;
});
});
}
4 changes: 2 additions & 2 deletions docker/.env-sample
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Neo4J free does not support custom db_name and db_username
# the default ones are neo4j
# Neo4J Community Edition does not support custom db_name and db_username
# the default ones are `neo4j`
NEO4J_DB_NAME=neo4j
NEO4J_DB_USERNAME=neo4j
NEO4J_PASSWORD=12345678
36 changes: 0 additions & 36 deletions examples/from_file.rs

This file was deleted.

6 changes: 3 additions & 3 deletions examples/stress_network_sim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use pubky_app_specs::{
PubkyAppBlob, PubkyAppFile, PubkyAppFollow, PubkyAppPost, PubkyAppPostKind, PubkyAppTag,
PubkyAppUser,
};
use pubky_nexus::Config;
use rand::rngs::StdRng;
use rand::{distributions::Alphanumeric, Rng, SeedableRng};
use rand_distr::{Distribution, LogNormal};
Expand Down Expand Up @@ -36,7 +35,7 @@ static MAX_FILES: usize = 10000;
async fn main() -> Result<()> {
let total_start = Instant::now(); // Start timing the whole script

let config = Config::from_env();
//let config = Config::from_env();

// Initialize the Client based on configuration
// let client = match config.testnet {
Expand All @@ -48,7 +47,8 @@ async fn main() -> Result<()> {
let client = Client::builder().build()?;

// Convert the homeserver from the config into a PublicKey
let homeserver = PublicKey::try_from(config.homeserver.as_str())?;
// Hard code from now homeserver pubky. This is a testnet default key
let homeserver = PublicKey::try_from("8pinxxgqs41n4aididenw5apqp1urfmzdztr8jt4abrkdn435ewo")?;

let mut rng = StdRng::seed_from_u64(SEED);
println!("Using seed: {}", SEED);
Expand Down
Loading

0 comments on commit 053cb90

Please sign in to comment.