Skip to content

Commit 2c3e0d3

Browse files
authored
feat(admin): downgrade protrial (#2042)
1 parent 4cd8fac commit 2c3e0d3

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

admin/src/args.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,4 +117,6 @@ pub enum Command {
117117
/// user id / project id / email
118118
query: String,
119119
},
120+
121+
DowngradeProTrials,
120122
}

admin/src/client.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,17 @@ impl Client {
167167

168168
Ok(())
169169
}
170+
171+
pub async fn get_expired_protrials(&self) -> Result<Vec<String>> {
172+
self.inner.get_json("/admin/users/protrial-downgrade").await
173+
}
174+
175+
pub async fn downgrade_protrial(&self, user_id: &str) -> Result<String> {
176+
self.inner
177+
.put_json(
178+
format!("/admin/users/protrial-downgrade/{user_id}"),
179+
Option::<()>::None,
180+
)
181+
.await
182+
}
170183
}

admin/src/lib.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,20 @@ pub async fn run(args: Args) {
150150
let v = client.get_user_everything(&query).await.unwrap();
151151
println!("{}", serde_json::to_string_pretty(&v).unwrap());
152152
}
153+
Command::DowngradeProTrials => {
154+
let users = client.get_expired_protrials().await.unwrap();
155+
eprintln!(
156+
"Starting downgrade of {} users in 5 seconds...",
157+
users.len()
158+
);
159+
tokio::time::sleep(tokio::time::Duration::from_millis(5000)).await;
160+
for user_id in users {
161+
println!("{user_id}");
162+
println!(" {:?}", client.downgrade_protrial(&user_id).await);
163+
// prevent api rate limiting
164+
tokio::time::sleep(tokio::time::Duration::from_millis(1000)).await;
165+
}
166+
}
153167
};
154168
}
155169

0 commit comments

Comments
 (0)