Skip to content

Commit bb0bf74

Browse files
committed
small fix on start_oracle now named serve
1 parent 89a6297 commit bb0bf74

File tree

3 files changed

+27
-19
lines changed

3 files changed

+27
-19
lines changed

core/src/cli/commands/coordinator/mod.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ mod view;
1212

1313
impl DriaOracle {
1414
/// Starts the oracle node.
15-
pub(in crate::cli) async fn start_oracle(
15+
pub(in crate::cli) async fn serve(
1616
&self,
1717
from_block: Option<BlockNumberOrTag>,
1818
to_block: Option<BlockNumberOrTag>,
@@ -40,7 +40,7 @@ impl DriaOracle {
4040
log::debug!("Cancellation signal received. Stopping...");
4141
return Ok(());
4242
}
43-
result = self.process_tasks_within_range(from_block, to_block.unwrap_or(BlockNumberOrTag::Latest)) => {
43+
result = self.process_tasks_within_range(from_block, to_block.clone().unwrap_or(BlockNumberOrTag::Latest)) => {
4444
if let Err(e) = result {
4545
log::error!("Could not handle previous tasks: {:?}", e);
4646
log::warn!("Continuing anyways...");
@@ -49,6 +49,12 @@ impl DriaOracle {
4949
}
5050
}
5151

52+
if to_block.is_some() {
53+
// if there was a `to_block` specified, we are done at this point
54+
return Ok(());
55+
}
56+
57+
// otherwise, we can continue with the event loop
5258
loop {
5359
// subscribe to new tasks
5460
log::info!("Subscribing to task events");

core/src/cli/commands/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ pub enum Commands {
3232
Claim,
3333
/// Serve the oracle node.
3434
Serve {
35-
#[arg(help = "The oracle kinds to handle tasks as.", required = false, value_parser = parse_oracle_kind)]
35+
#[arg(short, long = "kind", help = "The oracle kinds to handle tasks as, if omitted will default to all registered kinds.", value_parser = parse_oracle_kind)]
3636
kinds: Vec<OracleKind>,
3737
#[arg(short, long = "model", help = "The models to serve.", required = true, value_parser = parse_model)]
3838
models: Vec<Model>,
@@ -48,8 +48,8 @@ pub enum Commands {
4848
value_parser = parse_block_number_or_tag
4949
)]
5050
to: Option<BlockNumberOrTag>,
51-
#[arg(help = "Task id.", required = true)]
52-
task_id: U256,
51+
#[arg(help = "Optional task id to serve specifically.", required = false)]
52+
task_id: Option<U256>,
5353
},
5454
/// View tasks. fsdkhfk fsdkjfdks
5555
View {

core/src/cli/mod.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,23 @@ pub async fn handle_command(command: Commands, mut node: crate::DriaOracle) -> R
5959
let token = CancellationToken::new();
6060
node.prepare_oracle(kinds, models).await?;
6161

62-
// create a signal handler
63-
let termination_token = token.clone();
64-
let termination_handle = tokio::spawn(async move {
65-
wait_for_termination(termination_token).await.unwrap();
66-
});
67-
68-
// launch node
69-
node.start_oracle(from, to, token).await?;
70-
71-
// wait for handle
72-
if let Err(e) = termination_handle.await {
73-
log::error!("Error in termination handler: {}", e);
62+
if let Some(task_id) = task_id {
63+
node.process_task_by_id(task_id).await?
64+
} else {
65+
// create a signal handler
66+
let termination_token = token.clone();
67+
let termination_handle = tokio::spawn(async move {
68+
wait_for_termination(termination_token).await.unwrap();
69+
});
70+
71+
// launch node
72+
node.serve(from, to, token).await?;
73+
74+
// wait for handle
75+
if let Err(e) = termination_handle.await {
76+
log::error!("Error in termination handler: {}", e);
77+
}
7478
}
75-
76-
node.process_task_by_id(task_id).await?
7779
}
7880
Commands::View { task_id, from, to } => {
7981
if let Some(task_id) = task_id {

0 commit comments

Comments
 (0)