-
Notifications
You must be signed in to change notification settings - Fork 43
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Paul Quinn
committed
Dec 27, 2024
1 parent
ec8e240
commit 4447231
Showing
12 changed files
with
253 additions
and
196 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ | |
|
||
# IDE stuff | ||
.idea/ | ||
.vscode/ | ||
|
||
# Allow developers to use python pre-commit locally | ||
/.pre-commit-config.yaml |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Orb Fleet Commander | ||
|
||
This is the Orb Fleet Commander. It is a process the connects to the Fleet Backend to allow for fleet management. | ||
This is the Orb Fleet Commander. It is a process the connects to the Orb Relay Service and processes messages for fleet management. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,71 @@ | ||
pub mod args; | ||
pub mod settings; | ||
pub mod orb_info; | ||
pub mod settings; | ||
|
||
use color_eyre::eyre::{eyre, Result}; | ||
use orb_build_info::{make_build_info, BuildInfo}; | ||
use orb_endpoints::{Endpoints, OrbId}; | ||
use orb_relay_client::client::Client; | ||
use orb_relay_messages::common; | ||
use std::time::Duration; | ||
use tracing::error; | ||
|
||
pub const BUILD_INFO: BuildInfo = make_build_info!(); | ||
|
||
const ORB_FLEET_CMDR_NAMESPACE: &str = "orb-fleet-cmdr"; | ||
const ORB_RELAY_DEST_ID: &str = "orb-fleet-cmdr"; | ||
|
||
pub async fn relay_connect( | ||
orb_id: &OrbId, | ||
orb_token: String, | ||
endpoints: &Endpoints, | ||
reties: u32, | ||
timeout: Duration, | ||
) -> Result<Client> { | ||
let mut relay = Client::new_as_orb( | ||
endpoints.relay.to_string(), | ||
orb_token, | ||
orb_id.to_string(), | ||
ORB_RELAY_DEST_ID.to_string(), | ||
ORB_FLEET_CMDR_NAMESPACE.to_string(), | ||
); | ||
if let Err(e) = relay.connect().await { | ||
return Err(eyre!("Relay: Failed to connect: {e}")); | ||
} | ||
for _ in 0..reties { | ||
if let Ok(()) = relay | ||
.send_blocking( | ||
common::v1::AnnounceOrbId { | ||
orb_id: orb_id.to_string(), | ||
mode_type: common::v1::announce_orb_id::ModeType::SelfServe.into(), | ||
hardware_type: common::v1::announce_orb_id::HardwareType::Pearl | ||
.into(), | ||
}, | ||
timeout, | ||
) | ||
.await | ||
{ | ||
// Happy path. We have successfully announced and acknowledged the OrbId. | ||
return Ok(relay); | ||
} | ||
error!("Relay: Failed to AnnounceOrbId. Retrying..."); | ||
relay.reconnect().await?; | ||
if relay.has_pending_messages().await? > 0 { | ||
tokio::time::sleep(Duration::from_secs(1)).await; | ||
} | ||
} | ||
Err(eyre!( | ||
"Relay: Failed to send AnnounceOrbId after a reconnect" | ||
)) | ||
} | ||
|
||
pub async fn relay_disconnect( | ||
relay: &mut Client, | ||
wait_for_pending_messages: Duration, | ||
wait_for_shutdown: Duration, | ||
) -> Result<()> { | ||
relay | ||
.graceful_shutdown(wait_for_pending_messages, wait_for_shutdown) | ||
.await; | ||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.