-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add CLI for fetching sp promotions (#886)
* Add CLI for fetching sp promotions Fetch from mobile-config the same way they as the rewarder does. Print them in a nice little list. * Pass epoch_start when fetching promotions * Update tests for passing epoch_start for promotions
- Loading branch information
1 parent
6c67e36
commit fc79a09
Showing
8 changed files
with
61 additions
and
7 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
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,4 @@ | ||
pub mod reward_from_db; | ||
pub mod server; | ||
pub mod service_provider_promotions; | ||
pub mod verify_disktree; |
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 |
---|---|---|
@@ -0,0 +1,39 @@ | ||
use crate::{service_provider, Settings}; | ||
use anyhow::Result; | ||
use chrono::{DateTime, Utc}; | ||
use mobile_config::client::CarrierServiceClient; | ||
|
||
#[derive(Debug, clap::Args)] | ||
pub struct Cmd { | ||
#[clap(long)] | ||
start: Option<DateTime<Utc>>, | ||
} | ||
|
||
impl Cmd { | ||
pub async fn run(self, settings: &Settings) -> Result<()> { | ||
let epoch_start = match self.start { | ||
Some(dt) => dt, | ||
None => Utc::now(), | ||
}; | ||
|
||
let carrier_client = CarrierServiceClient::from_settings(&settings.config_client)?; | ||
let promos = service_provider::get_promotions(&carrier_client, &epoch_start).await?; | ||
|
||
println!("Promotions as of {epoch_start}"); | ||
for sp in promos.into_proto() { | ||
println!("Service Provider: {:?}", sp.service_provider()); | ||
println!(" incentive_escrow_bps: {:?}", sp.incentive_escrow_fund_bps); | ||
println!(" Promotions: ({})", sp.promotions.len()); | ||
for promo in sp.promotions { | ||
let start = DateTime::from_timestamp(promo.start_ts as i64, 0).unwrap(); | ||
let end = DateTime::from_timestamp(promo.end_ts as i64, 0).unwrap(); | ||
let duration = humantime::format_duration((end - start).to_std()?); | ||
println!(" name: {}", promo.entity); | ||
println!(" duration: {duration} ({start:?} -> {end:?})",); | ||
println!(" shares: {}", promo.shares); | ||
} | ||
} | ||
|
||
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
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