(&self, i: &CheckVoteInput)
| 298 | /// checked in `MAX_VOTE_CHECK_FREQUENCY`. |
| 299 | #[instrument(fields(vote_id), skip_all, err(Debug))] |
| 300 | async fn check_vote(&self, i: &CheckVoteInput) -> Result<()> { |
| 301 | // Get open vote (if any) from database |
| 302 | let Some(vote) = self |
| 303 | .db |
| 304 | .get_open_vote(&i.repository_full_name, i.issue_number) |
| 305 | .await |
| 306 | .context("error getting open vote")? |
| 307 | else { |
| 308 | return Ok(()); |
| 309 | }; |
| 310 | |
| 311 | // Record vote_id as part of the current span |
| 312 | tracing::Span::current().record("vote_id", vote.vote_id.to_string()); |
| 313 | |
| 314 | // Check if the vote has already been checked recently |
| 315 | let inst_id = vote.installation_id as u64; |
| 316 | let (owner, repo) = split_full_name(&vote.repository_full_name); |
| 317 | if let Some(checked_at) = vote.checked_at |
| 318 | && OffsetDateTime::now_utc() - checked_at < MAX_VOTE_CHECK_FREQUENCY |
| 319 | { |
| 320 | // Post comment on the issue/pr and return |
| 321 | let body = tmpl::VoteCheckedRecently {}.render()?; |
| 322 | self.gh.post_comment(inst_id, owner, repo, vote.issue_number, &body).await?; |
| 323 | return Ok(()); |
| 324 | } |
| 325 | |
| 326 | // Calculate results |
| 327 | let (owner, repo) = split_full_name(&vote.repository_full_name); |
| 328 | let results = results::calculate(self.gh.clone(), owner, repo, &vote).await?; |
| 329 | |
| 330 | // Post vote status comment on the issue/pr |
| 331 | let body = tmpl::VoteStatus::new(&results).render()?; |
| 332 | self.gh.post_comment(inst_id, owner, repo, vote.issue_number, &body).await?; |
| 333 | |
| 334 | // Update vote's last check ts |
| 335 | self.db.update_vote_last_check(vote.vote_id).await?; |
| 336 | |
| 337 | Ok(()) |
| 338 | } |
| 339 | } |
| 340 | |
| 341 | /// Worker that periodically checks the database for votes that should be |
no test coverage detected