Skip to content

Commit

Permalink
Merge pull request #41 from gevulotnetwork/feature/reschedule-client-…
Browse files Browse the repository at this point in the history
…infrastructure

add gevulot client infrastructure for rescheduling tasks
  • Loading branch information
trusch authored Jan 8, 2025
2 parents 64755bb + 9501e71 commit 9aad7a9
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 9 deletions.
18 changes: 18 additions & 0 deletions src/builders.rs
Original file line number Diff line number Diff line change
Expand Up @@ -436,3 +436,21 @@ impl MsgSudoFreezeAccountBuilder {
})
}
}

#[derive(Builder)]
pub struct MsgRescheduleTask {
pub creator: String,
pub task_id: String,
}

impl MsgRescheduleTaskBuilder {
pub fn into_message(&self) -> Result<gevulot::MsgRescheduleTask> {
let msg = self
.build()
.map_err(|e| Error::EncodeError(e.to_string()))?;
Ok(gevulot::MsgRescheduleTask {
creator: msg.creator,
id: msg.task_id,
})
}
}
2 changes: 1 addition & 1 deletion src/events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,7 +789,7 @@ mod tests {
assert_eq!(event.block_height, Height::from(1000u32));
assert_eq!(event.cid, "QmYwMXeEc3Z64vqcPXx8p8Y8Y5tE9Y5sYW42FZ1U87Y");
assert_eq!(event.worker_id, "worker1");
assert_eq!(event.success, true);
assert!(event.success);
assert_eq!(event.id, "123");
} else {
panic!("Unexpected event type");
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ mod tests {
assert_eq!(result.mounts[0].fstype, None);
assert_eq!(result.mounts[0].flags, None);
assert_eq!(result.mounts[0].data, None);
assert_eq!(result.default_mounts, true);
assert!(result.default_mounts);
assert_eq!(result.kernel_modules, vec!["nvidia".to_string()]);
assert_eq!(result.debug_exit, Some(DebugExit::default_x86()));
assert_eq!(result.bootcmd, vec![vec!["echo", "booting"]]);
Expand Down
8 changes: 2 additions & 6 deletions src/signer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,11 @@ impl Signer {
derivation: Option<&str>,
password: Option<&str>,
) -> Result<(SigningKey, PublicKey, AccountId)> {
let derivation = if let Some(derivation) = derivation {
derivation
} else {
"m/44'/118'/0'/0/0"
};
let derivation = derivation.unwrap_or("m/44'/118'/0'/0/0");

let mnemonic = Mnemonic::new(phrase, Language::English)?;
let pri = XPrv::derive_from_path(
&mnemonic.to_seed(password.unwrap_or("")),
mnemonic.to_seed(password.unwrap_or("")),
&derivation.parse()?,
)?;
let private_key = SigningKey::from(pri);
Expand Down
24 changes: 23 additions & 1 deletion src/task_client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use crate::{
proto::gevulot::gevulot::{
MsgAcceptTask, MsgAcceptTaskResponse, MsgCreateTask, MsgCreateTaskResponse, MsgDeclineTask,
MsgDeclineTaskResponse, MsgDeleteTask, MsgDeleteTaskResponse, MsgFinishTask,
MsgFinishTaskResponse,
MsgFinishTaskResponse, MsgRescheduleTask, MsgRescheduleTaskResponse,
},
};

Expand Down Expand Up @@ -191,4 +191,26 @@ impl TaskClient {
.await?;
Ok(resp)
}

/// Reschedules a task.
///
/// # Arguments
///
/// * `msg` - The message containing the task ID to reschedule.
///
/// # Returns
///
/// A Result containing the response or an error.
pub async fn reschedule(
&mut self,
msg: MsgRescheduleTask,
) -> Result<MsgRescheduleTaskResponse> {
let resp: MsgRescheduleTaskResponse = self
.base_client
.write()
.await
.send_msg_sync(msg, "")
.await?;
Ok(resp)
}
}

0 comments on commit 9aad7a9

Please sign in to comment.