Skip to main content

workyard_state/store/
placement.rs

1//! Refresh only location fields. Lifecycle and writer evidence may differ by document.
2use super::{Store, TaskGuard, evidence::effect_path};
3use crate::{
4	TaskRecord,
5	documents::{publish, read_versioned},
6	evidence::EffectRecord,
7	exists, revision,
8};
9use workyard_core::{Participant, Problem};
10
11impl Store {
12	/// Persist the participant's verified placement hint.
13	pub fn remember_participant(
14		&self,
15		guard: &TaskGuard,
16		participant: &Participant,
17	) -> Result<bool, Problem> {
18		self.verify()?;
19		guard.verify()?;
20		let anchor = TaskRecord::read(&guard.evidence_path)?;
21		let mut changed = false;
22		if let Some(mut revised) =
23			revision::read(&guard.evidence_path, &anchor, &self.root, &self.state)?
24		{
25			if revised
26				.current
27				.task
28				.refresh_location(participant, &self.state)?
29			{
30				publish(&revision::path(&guard.evidence_path), &revised)?;
31				changed = true;
32			}
33		} else {
34			let effects = effect_path(guard);
35			if exists(&effects)? {
36				let mut record: EffectRecord = read_versioned(&effects)?;
37				if record.task.refresh_location(participant, &self.state)? {
38					publish(&effects, &record)?;
39					changed = true;
40				}
41			}
42		}
43		let mut published = TaskRecord::read(&guard.record_path)?;
44		if published.refresh_location(participant, &self.state)? {
45			publish(&guard.record_path, &published)?;
46			changed = true;
47		}
48		Ok(changed)
49	}
50}