Skip to content

Commit 63f0b90

Browse files
committed
Using config
1 parent 9972a0c commit 63f0b90

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

src/agent/services/oracle.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,11 +67,11 @@ where
6767
)));
6868

6969
if config.oracle.subscriber_enabled {
70-
let number_of_workers = 100;
71-
let channel_size = 1000;
72-
let (sender, receiver) = tokio::sync::mpsc::channel(channel_size);
73-
let max_elapsed_time = Duration::from_secs(30);
74-
let sleep_time = Duration::from_secs(1);
70+
let number_of_workers = config.oracle.handle_price_account_update_worker_poll_size;
71+
let (sender, receiver) =
72+
tokio::sync::mpsc::channel(config.oracle.handle_price_account_update_channel_size);
73+
let min_elapsed_time = config.oracle.subscriber_finished_min_time;
74+
let sleep_time = config.oracle.subscriber_finished_sleep_time;
7575

7676
handles.push(tokio::spawn(async move {
7777
loop {
@@ -86,7 +86,7 @@ where
8686
.await
8787
{
8888
tracing::error!(?err, "Subscriber exited unexpectedly");
89-
if current_time.elapsed() < max_elapsed_time {
89+
if current_time.elapsed() < min_elapsed_time {
9090
tracing::warn!(?sleep_time, "Subscriber restarting too quickly. Sleeping");
9191
tokio::time::sleep(sleep_time).await;
9292
}

src/agent/state/oracle.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,22 @@ pub struct Data {
138138
pub publisher_buffer_key: Option<Pubkey>,
139139
}
140140

141+
fn default_handle_price_account_update_channel_size() -> usize {
142+
1000
143+
}
144+
145+
fn default_handle_price_account_update_worker_poll_size() -> usize {
146+
50
147+
}
148+
149+
fn default_subscriber_finished_min_time() -> Duration {
150+
Duration::from_secs(30)
151+
}
152+
153+
fn default_subscriber_finished_sleep_time() -> Duration {
154+
Duration::from_secs(1)
155+
}
156+
141157
#[derive(Clone, Serialize, Deserialize, Debug)]
142158
#[serde(default)]
143159
pub struct Config {
@@ -159,6 +175,19 @@ pub struct Config {
159175
/// socket count at bay, the batches are looked up sequentially,
160176
/// trading off overall time it takes to fetch all symbols.
161177
pub max_lookup_batch_size: usize,
178+
179+
/// Number of workers used to wait for the handle_price_account_update
180+
#[serde(default = "default_handle_price_account_update_worker_poll_size")]
181+
pub handle_price_account_update_worker_poll_size: usize,
182+
/// Channel size used to wait for the handle_price_account_update
183+
#[serde(default = "default_handle_price_account_update_channel_size")]
184+
pub handle_price_account_update_channel_size: usize,
185+
/// Minimum time for a subscriber to run
186+
#[serde(default = "default_subscriber_finished_min_time")]
187+
pub subscriber_finished_min_time: Duration,
188+
/// Time to sleep if the subscriber do not run for more than the minimum time
189+
#[serde(default = "default_subscriber_finished_sleep_time")]
190+
pub subscriber_finished_sleep_time: Duration,
162191
}
163192

164193
impl Default for Config {
@@ -170,6 +199,12 @@ impl Default for Config {
170199
updates_channel_capacity: 10000,
171200
data_channel_capacity: 10000,
172201
max_lookup_batch_size: 100,
202+
handle_price_account_update_worker_poll_size:
203+
default_handle_price_account_update_worker_poll_size(),
204+
handle_price_account_update_channel_size:
205+
default_handle_price_account_update_channel_size(),
206+
subscriber_finished_min_time: default_subscriber_finished_min_time(),
207+
subscriber_finished_sleep_time: default_subscriber_finished_sleep_time(),
173208
}
174209
}
175210
}

0 commit comments

Comments
 (0)