Skip to content

Commit

Permalink
Added scheduler event with relay list (#319)
Browse files Browse the repository at this point in the history
* added scheduler event with relay list

* fix for relay list kind
  • Loading branch information
arkanoider authored Jul 3, 2024
1 parent 7441d36 commit 46a617d
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 2 deletions.
3 changes: 2 additions & 1 deletion docker/settings.docker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ max_expiration_days = 15
expiration_seconds = 900
# User rate events scheduled time interval
user_rates_sent_interval_seconds = 3600

# Relay list event time interval
publish_relays_interval = 60


[database]
Expand Down
2 changes: 2 additions & 0 deletions settings.tpl.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ max_expiration_days = 15
expiration_seconds = 900
# User rate events scheduled time interval
user_rates_sent_interval_seconds = 3600
# Relay list event time interval
publish_relays_interval = 60



Expand Down
1 change: 1 addition & 0 deletions src/cli/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ pub struct Mostro {
pub expiration_seconds: u32,
pub user_rates_sent_interval_seconds: u32,
pub max_expiration_days: u32,
pub publish_relays_interval: u32,
}

impl TryFrom<Settings> for Mostro {
Expand Down
33 changes: 32 additions & 1 deletion src/scheduler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use crate::NOSTR_CLIENT;

use chrono::{TimeDelta, Utc};
use mostro_core::order::{Kind, Status};
use nostr_sdk::Event;
use nostr_sdk::EventBuilder;
use nostr_sdk::{Event, Kind as NostrKind, Tag, Url};
use sqlx_crud::Crud;
use std::str::FromStr;
use std::sync::Arc;
use tokio::sync::Mutex;
use tracing::{error, info};
Expand All @@ -22,10 +24,39 @@ pub async fn start_scheduler(rate_list: Arc<Mutex<Vec<Event>>>) {
job_cancel_orders().await;
job_retry_failed_payments().await;
job_info_event_send().await;
job_relay_list().await;

info!("Scheduler Started");
}

async fn job_relay_list() {
let mostro_pubkey = match get_keys() {
Ok(keys) => keys,
Err(e) => return error!("{e}"),
};

tokio::spawn(async move {
loop {
info!("Sending Mostro relay list");

let interval = Settings::get_mostro().publish_relays_interval as u64;
let relay_list = Settings::get_nostr().relays;
let mut relay_tags: Vec<Tag> = vec![];

for r in relay_list {
relay_tags.push(Tag::relay_metadata(Url::from_str(&r).unwrap(), None))
}

if let Ok(relay_ev) =
EventBuilder::new(NostrKind::RelayList, "", relay_tags).to_event(&mostro_pubkey)
{
let _ = NOSTR_CLIENT.get().unwrap().send_event(relay_ev).await;
}
tokio::time::sleep(tokio::time::Duration::from_secs(interval)).await;
}
});
}

async fn job_info_event_send() {
let mostro_pubkey = match get_keys() {
Ok(keys) => keys,
Expand Down

0 comments on commit 46a617d

Please sign in to comment.