Skip to content

Commit

Permalink
Faster health endpoint setup + rate limit logging
Browse files Browse the repository at this point in the history
  • Loading branch information
dcadenas committed Sep 27, 2024
1 parent a9ecc47 commit e43bd7a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 15 deletions.
25 changes: 13 additions & 12 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,21 @@ async fn start(settings: Settings) -> Result<()> {
let repo = Arc::new(Repo::new(graph));

repo.log_neo4j_details().await?;
let shared_nostr_client = Arc::new(create_client());
let task_tracker = TaskTracker::new();
let cancellation_token = CancellationToken::new();

// Leave the http server at the top so the health endpoint is available quickly
info!("Starting HTTP server at port {}", settings.http_port);
HttpServer::start(
task_tracker.clone(),
&settings,
repo.clone(),
shared_nostr_client.clone(),
cancellation_token.clone(),
)?;

info!("Initializing workers for follower list diff calculation");
let shared_nostr_client = Arc::new(create_client());
let (follow_change_sender, _) =
broadcast::channel::<Box<FollowChange>>(settings.follow_change_channel_size.get());
let follows_differ_worker = FollowsDiffer::new(
Expand All @@ -107,8 +119,6 @@ async fn start(settings: Settings) -> Result<()> {
follow_change_sender.clone(),
);

let task_tracker = TaskTracker::new();
let cancellation_token = CancellationToken::new();
let (event_sender, event_receiver) =
broadcast::channel::<Box<Event>>(settings.event_channel_size.get());
WorkerPool::start(
Expand Down Expand Up @@ -175,15 +185,6 @@ async fn start(settings: Settings) -> Result<()> {
.await
.context("Failed starting the scheduler")?;

info!("Starting HTTP server at port {}", settings.http_port);
HttpServer::start(
task_tracker.clone(),
&settings,
repo,
shared_nostr_client,
cancellation_token.clone(),
)?;

tokio::spawn(async move {
if let Err(e) = cancel_on_stop_signals(cancellation_token).await {
error!("Failed to listen stop signals: {}", e);
Expand Down
3 changes: 0 additions & 3 deletions src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,6 @@ pub async fn start_scheduler<T>(
where
T: RepoTrait + 'static,
{
// For the moment ensure we always trigger one update on startup
refresh_pagerank(repo.clone()).await;

// And then once every day
let mut sched = JobScheduler::new().await?;
let cron_expression = settings.pagerank_cron_expression.as_str();
Expand Down

0 comments on commit e43bd7a

Please sign in to comment.