Skip to content

Commit

Permalink
Merge pull request #41 from ictsc/integration-with-rstate
Browse files Browse the repository at this point in the history
Status周りを修正した
  • Loading branch information
proelbtn authored Nov 18, 2023
2 parents 70879f9 + 58fbddc commit 566e836
Show file tree
Hide file tree
Showing 5 changed files with 127 additions and 13 deletions.
91 changes: 91 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ anyhow = "1.0.53"
async-trait = "0.1.52"
base64 = "0.13.0"
chrono = { version = "0.4.31", features = ["serde"] }
chrono-tz = "0.8.4"
clap = { version = "4.4.2", features = ["derive"] }
derive_builder = "0.12.0"
reqwest = { version = "0.11.9", features = ["json"] }
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ NAME ?= ictsc-discord-bot
IMAGE_TAG ?= latest
IMAGE ?= ghcr.io/ictsc/ictsc-discord-bot:$(IMAGE_TAG)

DOCKER_ARGS ?= -v "$(shell pwd)/bot.yaml:/bot.yaml" --net host --env RUST_LOG=info,bot=debug
DOCKER_ARGS ?= -v "$(shell pwd)/bot.yaml:/bot.yaml" --net host --env RUST_LOG=info,bot=trace

all:

Expand Down
37 changes: 27 additions & 10 deletions src/bot/commands/redeploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -322,17 +322,34 @@ impl Bot {
self.edit_response(interaction, |data| {
data.embed(|e| {
e.title("再展開状況");
// TODO: 再展開状況はいい感じに表示する。今日はもう疲れた。
for status in &statuses {
if status.last_redeploy_started_at.is_none() {
continue;
}

e.field(
&status.problem_code,
format!("{}", status.is_redeploying),
false,
);
let started_at = match status.last_redeploy_started_at {
Some(started_at) => started_at,
None => continue,
};

let name = &status.problem_code;

let value = match status.last_redeploy_completed_at {
Some(completed_at) => {
let completed_at_local =
completed_at.with_timezone(&chrono_tz::Asia::Tokyo);
format!(
"🎉 再展開完了(完了時刻:{})",
completed_at_local.format("%Y/%m/%d %H:%M:%S")
)
},
None => {
let started_at_local =
started_at.with_timezone(&chrono_tz::Asia::Tokyo);
format!(
"⚙️ 再展開中(開始時刻:{})",
started_at_local.format("%Y/%m/%d %H:%M:%S")
)
},
};

e.field(name, value, false);
}
e
})
Expand Down
9 changes: 7 additions & 2 deletions src/services/redeploy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -125,12 +125,15 @@ impl RedeployService for RState {
async fn redeploy(&self, target: &RedeployTarget) -> RedeployResult<RedeployJob> {
tracing::info!("redeploy request received");

// RStateでは、問題コードは小文字で取り扱う必要がある。
let problem_id = target.problem_id.to_lowercase();

let response = self
.client
.post(format!("{}/admin/postJob", self.config.baseurl))
.form(&RStatePostJobRequest {
team_id: &target.team_id,
prob_id: &target.problem_id,
prob_id: &problem_id,
})
.basic_auth(&self.config.username, Some(&self.config.password))
.send()
Expand Down Expand Up @@ -169,11 +172,13 @@ impl RedeployService for RState {

let mut statuses = Vec::new();
for problem in &self.config.problems {
// RStateでは、問題コードは小文字で取り扱う必要がある。
let problem_code = problem.code.to_lowercase();
let response = self
.client
.get(format!(
"{}/backend/{}/{}",
self.config.baseurl, team_id, problem.code
self.config.baseurl, team_id, problem_code
))
.send()
.await?;
Expand Down

0 comments on commit 566e836

Please sign in to comment.