Skip to content

Commit

Permalink
Fix spot-updating of first session of the month
Browse files Browse the repository at this point in the history
  • Loading branch information
Celeo committed Feb 1, 2025
1 parent 9bbfe0d commit 8b58ba4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
1 change: 1 addition & 0 deletions vzdv-site/templates/changelog.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
<div class="card-text">
<ul>
<li>Update training link to hosted Scheddy</li>
<li>Fix spot-updating activity for first-of-the-month controlling session</li>
</ul>
</div>
</div>
Expand Down
16 changes: 15 additions & 1 deletion vzdv-tasks/src/activity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,27 @@ async fn update_single_activity(
let logon_time = DateTime::parse_from_rfc3339(logon_time)?.timestamp();
let online_seconds = Utc::now().timestamp() - logon_time;
let minutes = ((counter + online_seconds as f32) / 60.0).round() as u32;
sqlx::query(sql::UPDATE_ACTIVITY)

// update the controller's time for this month (if able)
let result = sqlx::query(sql::UPDATE_ACTIVITY)
.bind(cid as u32)
.bind(start_of_month[0..7].to_string())
.bind(minutes)
.execute(db)
.await
.with_context(|| format!("Updating CID {cid}"))?;
if result.rows_affected() == 0 {
// The controller hasn't yet completed a full session for this month,
// so no rows were updated. Insert a new row.
sqlx::query(sql::INSERT_INTO_ACTIVITY)
.bind(cid as u32)
.bind(start_of_month[0..7].to_string())
.bind(minutes)
.execute(db)
.await
.with_context(|| format!("Inserting new activity row for spot-update for {cid}"))?;
}

Ok(())
}

Expand Down

0 comments on commit 8b58ba4

Please sign in to comment.