Skip to content

Commit b8e23ea

Browse files
committed
[integritee-service/teeracle] renamed interval to periodic/period to align with the substrate terms used in the scheduler pallet.
1 parent 68e37f7 commit b8e23ea

File tree

3 files changed

+16
-15
lines changed

3 files changed

+16
-15
lines changed

service/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#![cfg_attr(test, feature(assert_matches))]
1919

2020
#[cfg(feature = "teeracle")]
21-
use crate::teeracle::{schedule_teeracle_reregistration_thread, start_interval_market_update};
21+
use crate::teeracle::{schedule_teeracle_reregistration_thread, start_periodic_market_update};
2222

2323
#[cfg(not(feature = "dcap"))]
2424
use crate::utils::check_files;
@@ -483,7 +483,7 @@ fn start_worker<E, T, D, InitializationHandler, WorkerModeProvider>(
483483
run_config.reregister_teeracle_interval(),
484484
);
485485

486-
start_interval_market_update(
486+
start_periodic_market_update(
487487
&node_api,
488488
run_config.teeracle_update_interval(),
489489
enclave.as_ref(),

service/src/teeracle/mod.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
1616
*/
1717

18-
use crate::{error::ServiceResult, teeracle::interval_scheduling::schedule_on_repeating_intervals};
18+
use crate::{error::ServiceResult, teeracle::schedule_periodic::schedule_periodic};
1919
use codec::{Decode, Encode};
2020
use itp_enclave_api::teeracle_api::TeeracleApi;
2121
use itp_node_api::api_client::ParentchainApi;
@@ -28,7 +28,7 @@ use substrate_api_client::{SubmitAndWatch, XtStatus};
2828
use teeracle_metrics::{increment_number_of_request_failures, set_extrinsics_inclusion_success};
2929
use tokio::runtime::Handle;
3030

31-
pub(crate) mod interval_scheduling;
31+
pub(crate) mod schedule_periodic;
3232
pub(crate) mod teeracle_metrics;
3333

3434
pub(crate) fn schedule_teeracle_reregistration_thread(
@@ -40,7 +40,7 @@ pub(crate) fn schedule_teeracle_reregistration_thread(
4040
std::thread::Builder::new()
4141
.name("teeracle_reregistration_thread".to_owned())
4242
.spawn(move || {
43-
schedule_on_repeating_intervals(
43+
schedule_periodic(
4444
|| {
4545
println!("Reregistering the teeracle.");
4646
if let Some(block_hash) = send_register_xt() {
@@ -58,11 +58,12 @@ pub(crate) fn schedule_teeracle_reregistration_thread(
5858
.unwrap();
5959
}
6060

61-
/// Send extrinsic to chain according to the market data update interval in the settings
62-
/// with the current market data (for now only exchange rate).
63-
pub(crate) fn start_interval_market_update<E: TeeracleApi>(
61+
/// Executes a periodic teeracle data update and sends the new data to the parentchain.
62+
///
63+
/// Note: Puts the current thread to sleep for `period`.
64+
pub(crate) fn start_periodic_market_update<E: TeeracleApi>(
6465
api: &ParentchainApi,
65-
interval: Duration,
66+
period: Duration,
6667
enclave_api: &E,
6768
tokio_handle: &Handle,
6869
) {
@@ -84,8 +85,8 @@ pub(crate) fn start_interval_market_update<E: TeeracleApi>(
8485
info!("Teeracle will update now");
8586
updates_to_run();
8687

87-
info!("Schedule teeracle updates every {:?}", interval);
88-
schedule_on_repeating_intervals(updates_to_run, interval);
88+
info!("Schedule teeracle updates every {:?}", period);
89+
schedule_periodic(updates_to_run, period);
8990
}
9091

9192
fn execute_oracle_update<F>(

service/src/teeracle/interval_scheduling.rs renamed to service/src/teeracle/schedule_periodic.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@ use std::{
2020
time::{Duration, Instant},
2121
};
2222

23-
/// Schedules a task on perpetually looping intervals.
23+
/// Schedules a periodic task in the current thread.
2424
///
2525
/// In case the task takes longer than is scheduled by the interval duration,
2626
/// the interval timing will drift. The task is responsible for
2727
/// ensuring it does not use up more time than is scheduled.
28-
pub(super) fn schedule_on_repeating_intervals<T>(task: T, interval_duration: Duration)
28+
pub(super) fn schedule_periodic<T>(task: T, period: Duration)
2929
where
3030
T: Fn(),
3131
{
3232
let mut interval_start = Instant::now();
3333
loop {
3434
let elapsed = interval_start.elapsed();
3535

36-
if elapsed >= interval_duration {
36+
if elapsed >= period {
3737
// update interval time
3838
interval_start = Instant::now();
3939
task();
4040
} else {
4141
// sleep for the rest of the interval
42-
let sleep_time = interval_duration - elapsed;
42+
let sleep_time = period - elapsed;
4343
thread::sleep(sleep_time);
4444
}
4545
}

0 commit comments

Comments
 (0)