forked from yvv/decision
WIP lot V : le tampon câblé dans le serveur (migration 0010, simulation, discard-simulation), tests en cours de reprise — repris tel quel après la coupure du 02/11
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -4,7 +4,8 @@
|
||||
//! and runs four background workers: the electorate refresher (size of the Ğ1
|
||||
//! web of trust), the adoption sweeper (with the deadlines of three days of
|
||||
//! objections and typo fixes), the ballot watcher (votes signed on the Ğ1 chain,
|
||||
//! confirmed on the indexer) and the publisher (adopted texts pushed to the git
|
||||
//! confirmed on the indexer, or simulated while the chain is closed — ADR 0012)
|
||||
//! and the publisher (adopted texts pushed to the git
|
||||
//! repository that client applications read).
|
||||
|
||||
pub mod access;
|
||||
@@ -30,6 +31,7 @@ pub mod proposals;
|
||||
pub mod publish;
|
||||
pub mod seed;
|
||||
pub mod seed_amend;
|
||||
pub mod simulation;
|
||||
pub mod team;
|
||||
pub mod typos;
|
||||
pub mod util;
|
||||
@@ -46,6 +48,7 @@ use sqlx::SqlitePool;
|
||||
use sqlx::sqlite::{SqliteConnectOptions, SqliteJournalMode, SqlitePoolOptions};
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::time::Duration;
|
||||
use tokio::sync::Notify;
|
||||
|
||||
@@ -62,6 +65,9 @@ pub struct AppState {
|
||||
pub upcoming: Arc<overview::Upcoming>,
|
||||
/// The clock of the deadlines of three days (objections, typo fixes); tests move it.
|
||||
pub clock: clock::Clock,
|
||||
/// Tests only, with the dev login: the chain of this server closed for a while
|
||||
/// (`POST /api/dev/vote-chain`), to try the simulation (ADR 0012).
|
||||
pub chain_closed: Arc<AtomicBool>,
|
||||
}
|
||||
|
||||
impl AppState {
|
||||
@@ -78,8 +84,20 @@ impl AppState {
|
||||
publish_wake: Arc::new(Notify::new()),
|
||||
upcoming,
|
||||
clock: clock::Clock::default(),
|
||||
chain_closed: Arc::new(AtomicBool::new(false)),
|
||||
})
|
||||
}
|
||||
|
||||
/// The vote on the chain, as it is now: `None` while it is closed (no vote
|
||||
/// account, or closed for a test) — the vote is then simulated (ADR 0012).
|
||||
pub fn chain(&self) -> Option<&config::VoteChain> {
|
||||
self.cfg.vote.as_ref().filter(|_| !self.chain_closed.load(Ordering::Relaxed))
|
||||
}
|
||||
|
||||
/// What each stage of a vote weighs (ADR 0012).
|
||||
pub fn vote_rules(&self) -> ld_engine::buffer::Rules {
|
||||
ld_engine::buffer::Rules { simulated_adopts: self.cfg.simulated_adopts }
|
||||
}
|
||||
}
|
||||
|
||||
/// Open (or create) the database and apply migrations.
|
||||
@@ -159,6 +177,7 @@ pub fn api_router() -> Router<AppState> {
|
||||
.route("/messages/read", post(messages::read_all))
|
||||
.route("/messages/{id}/read", post(messages::read))
|
||||
.route("/dev/clock", post(deadlines::dev_clock))
|
||||
.route("/dev/vote-chain", post(ballots::dev_chain))
|
||||
.route("/units/{id}/inertia", post(proposals::propose_inertia))
|
||||
.route("/units/{id}/order", post(order::propose))
|
||||
.route("/units/{id}/title", post(doc_title::propose))
|
||||
|
||||
Reference in New Issue
Block a user