ffi: JobState crosses as itself; Failed names its message
JobItem.state was a snake_case tag beside an error field only Failed
ever set, and the Jobs screen compared the tag against "running",
"queued", "done" and "failed". JobState is now a uniffi::Enum and
JobItem carries it; Failed(String) becomes Failed { message } so Kotlin
reads .message rather than .v1. JobItem.error goes — Kotlin never read
it, since the failure already reaches it through status_line. (F4)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
651085adca
commit
dcd8ed77a6
8 files changed
+37
-36
No files matched your search
@@ -43,6 +43,7 @@ import kotlinx.coroutines.withContext
|
||||
import uniffi.synchronicity.ChangeChannel
|
||||
import uniffi.synchronicity.JobItem
|
||||
import uniffi.synchronicity.JobKind
|
||||
import uniffi.synchronicity.JobState
|
||||
import uniffi.synchronicity.jobHistoryTimes
|
||||
import uniffi.synchronicity.jobKindLabel
|
||||
|
||||
@@ -229,7 +230,7 @@ private fun JobRow(job: JobItem, showTimestamps: Boolean, timezone: String?, onC
|
||||
}
|
||||
}
|
||||
|
||||
if (job.state == "running" || job.state == "queued") {
|
||||
if (job.state is JobState.Running || job.state is JobState.Queued) {
|
||||
Row(
|
||||
horizontalArrangement = Arrangement.spacedBy(8.dp),
|
||||
verticalAlignment = Alignment.CenterVertically,
|
||||
@@ -290,8 +291,8 @@ private fun JobLabelRow(job: JobItem) {
|
||||
private fun JobStatusLine(job: JobItem) {
|
||||
val color =
|
||||
when (job.state) {
|
||||
"done" -> SynTheme.palette.colorSuccess
|
||||
"failed" -> MaterialTheme.colorScheme.error
|
||||
is JobState.Done -> SynTheme.palette.colorSuccess
|
||||
is JobState.Failed -> MaterialTheme.colorScheme.error
|
||||
else -> MaterialTheme.colorScheme.onSurfaceVariant
|
||||
}
|
||||
Text(text = job.statusLine, style = MaterialTheme.typography.labelSmall, color = color)
|
||||
@@ -307,7 +308,7 @@ private fun JobStatusLine(job: JobItem) {
|
||||
@Composable
|
||||
private fun JobProgressBar(job: JobItem) {
|
||||
val fraction = job.fractionDone
|
||||
if (job.state != "running" || fraction == null) return
|
||||
if (job.state !is JobState.Running || fraction == null) return
|
||||
LinearProgressIndicator(
|
||||
progress = { fraction },
|
||||
modifier = Modifier.fillMaxWidth().padding(top = 2.dp),
|
||||
|
||||
@@ -412,7 +412,7 @@ impl JobsView {
|
||||
fn render_status_line(&self, theme: &Theme, job: &Job) -> impl IntoElement {
|
||||
let color = match &job.state {
|
||||
JobState::Done => theme.color_success,
|
||||
JobState::Failed(_) => theme.color_error,
|
||||
JobState::Failed { .. } => theme.color_error,
|
||||
JobState::Queued | JobState::Running | JobState::Canceled => theme.text_secondary,
|
||||
};
|
||||
div().text_size(font::SMALL).text_color(color).child(job.status_line())
|
||||
|
||||
@@ -150,10 +150,7 @@ pub struct JobItem {
|
||||
/// already holds. Not for display, and not parsed back.
|
||||
pub match_key: String,
|
||||
pub label: String,
|
||||
/// Snake_case state name (`"queued"`, `"running"`, `"done"`, `"failed"`, `"canceled"`).
|
||||
pub state: String,
|
||||
/// Set only when `state == "failed"`.
|
||||
pub error: Option<String>,
|
||||
pub state: JobState,
|
||||
pub progress_message: Option<String>,
|
||||
/// The line under the label — [`Job::status_line`](crate::jobs::Job::status_line).
|
||||
pub status_line: String,
|
||||
@@ -215,18 +212,13 @@ pub(super) fn job_to_item(
|
||||
None => (None, None, false),
|
||||
};
|
||||
|
||||
let error = match &job.state {
|
||||
JobState::Failed(msg) => Some(msg.clone()),
|
||||
_ => None,
|
||||
};
|
||||
JobItem {
|
||||
status_line: job.status_line(),
|
||||
id: job.id.to_string(),
|
||||
kind: job.kind,
|
||||
match_key: jobs::match_key(job.kind, &job.subject),
|
||||
label: job.label,
|
||||
state: job.state.tag().to_string(),
|
||||
error,
|
||||
state: job.state,
|
||||
progress_message: job.progress.as_ref().and_then(|p| p.message.clone()),
|
||||
fraction_done: job.progress.as_ref().and_then(|p| p.fraction_done()),
|
||||
units_done: job.progress.as_ref().map(|p| p.units_done),
|
||||
|
||||
@@ -229,7 +229,7 @@ impl JobOrigin {
|
||||
}
|
||||
|
||||
/// Where a [`Job`] is in its lifecycle.
|
||||
#[derive(Debug, Clone, PartialEq, Eq)]
|
||||
#[derive(Debug, Clone, PartialEq, Eq, uniffi::Enum)]
|
||||
pub enum JobState {
|
||||
/// Not yet running. No job producer in this codebase queues today
|
||||
/// (see [`runner::JobRunner::start`]'s doc comment) — this variant
|
||||
@@ -237,7 +237,9 @@ pub enum JobState {
|
||||
Queued,
|
||||
Running,
|
||||
Done,
|
||||
Failed(String),
|
||||
Failed {
|
||||
message: String,
|
||||
},
|
||||
Canceled,
|
||||
}
|
||||
|
||||
@@ -259,7 +261,7 @@ impl JobState {
|
||||
JobState::Queued => "queued",
|
||||
JobState::Running => "running",
|
||||
JobState::Done => "done",
|
||||
JobState::Failed(_) => "failed",
|
||||
JobState::Failed { .. } => "failed",
|
||||
JobState::Canceled => "canceled",
|
||||
}
|
||||
}
|
||||
@@ -276,7 +278,7 @@ impl JobState {
|
||||
"queued" => Ok(JobState::Queued),
|
||||
"running" => Ok(JobState::Running),
|
||||
"done" => Ok(JobState::Done),
|
||||
"failed" => Ok(JobState::Failed(error.unwrap_or_default())),
|
||||
"failed" => Ok(JobState::Failed { message: error.unwrap_or_default() }),
|
||||
"canceled" => Ok(JobState::Canceled),
|
||||
other => Err(JobParseError::State(other.to_string())),
|
||||
}
|
||||
@@ -404,7 +406,7 @@ impl Job {
|
||||
pub fn status_line(&self) -> String {
|
||||
match &self.state {
|
||||
JobState::Running => self.progress.as_ref().and_then(|p| p.message.clone()),
|
||||
JobState::Failed(msg) => Some(msg.clone()),
|
||||
JobState::Failed { message } => Some(message.clone()),
|
||||
_ => None,
|
||||
}
|
||||
.unwrap_or_else(|| self.state.display_name().to_string())
|
||||
@@ -763,7 +765,7 @@ mod tests {
|
||||
|
||||
let history = store.job_store.batch(|tx| store.job_store.list_history(tx, 10)).unwrap();
|
||||
assert_eq!(history.len(), 1);
|
||||
assert_eq!(history[0].state, JobState::Failed("peer unreachable".to_string()));
|
||||
assert_eq!(history[0].state, JobState::Failed { message: "peer unreachable".to_string() });
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
|
||||
@@ -314,7 +314,7 @@ impl JobHandle {
|
||||
} else {
|
||||
match result {
|
||||
Ok(()) => JobState::Done,
|
||||
Err(msg) => JobState::Failed(msg),
|
||||
Err(msg) => JobState::Failed { message: msg },
|
||||
}
|
||||
};
|
||||
self.finish_with_state(state);
|
||||
@@ -351,9 +351,9 @@ impl ProgressReporter for JobHandle {
|
||||
impl Drop for JobHandle {
|
||||
fn drop(&mut self) {
|
||||
if !self.finished.load(Ordering::SeqCst) {
|
||||
self.finish_with_state(JobState::Failed(
|
||||
"job handle dropped without finishing".to_string(),
|
||||
));
|
||||
self.finish_with_state(JobState::Failed {
|
||||
message: "job handle dropped without finishing".to_string(),
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -413,7 +413,7 @@ mod tests {
|
||||
handle.finish(Err("peer unreachable".to_string()));
|
||||
|
||||
let job = store.job_store.batch(|tx| store.job_store.get(tx, id)).unwrap().unwrap();
|
||||
assert_eq!(job.state, JobState::Failed("peer unreachable".to_string()));
|
||||
assert_eq!(job.state, JobState::Failed { message: "peer unreachable".to_string() });
|
||||
}
|
||||
|
||||
#[rstest]
|
||||
@@ -456,7 +456,10 @@ mod tests {
|
||||
drop(handle);
|
||||
|
||||
let job = store.job_store.batch(|tx| store.job_store.get(tx, id)).unwrap().unwrap();
|
||||
assert_eq!(job.state, JobState::Failed("job handle dropped without finishing".to_string()));
|
||||
assert_eq!(
|
||||
job.state,
|
||||
JobState::Failed { message: "job handle dropped without finishing".to_string() }
|
||||
);
|
||||
|
||||
// And the dedup entry is cleared too, since drop calls finish_with_state.
|
||||
let again = runner.start(
|
||||
@@ -521,6 +524,6 @@ mod tests {
|
||||
assert!(runner.find_active(JobKind::CatalogSync, &peer(9)).is_none());
|
||||
|
||||
let job = store.job_store.batch(|tx| store.job_store.get(tx, orphan.id)).unwrap().unwrap();
|
||||
assert_eq!(job.state, JobState::Failed("interrupted by restart".to_string()));
|
||||
assert_eq!(job.state, JobState::Failed { message: "interrupted by restart".to_string() });
|
||||
}
|
||||
}
|
||||
@@ -147,7 +147,7 @@ pub struct JobSummary {
|
||||
impl From<&Job> for JobSummary {
|
||||
fn from(job: &Job) -> Self {
|
||||
let error = match &job.state {
|
||||
JobState::Failed(msg) => Some(msg.clone()),
|
||||
JobState::Failed { message } => Some(message.clone()),
|
||||
_ => None,
|
||||
};
|
||||
JobSummary {
|
||||
@@ -447,7 +447,7 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn job_summary_carries_the_failure_message() {
|
||||
let job = sample_job(JobKind::Eviction, JobState::Failed("disk full".into()));
|
||||
let job = sample_job(JobKind::Eviction, JobState::Failed { message: "disk full".into() });
|
||||
let summary = JobSummary::from(&job);
|
||||
assert_eq!(summary.error.as_deref(), Some("disk full"));
|
||||
assert_eq!(summary.state, "failed");
|
||||
|
||||
@@ -269,7 +269,7 @@ impl JobStore {
|
||||
/// `None` unless `state` is [`JobState::Failed`].
|
||||
fn error_text(state: &JobState) -> Option<&str> {
|
||||
match state {
|
||||
JobState::Failed(msg) => Some(msg.as_str()),
|
||||
JobState::Failed { message } => Some(message.as_str()),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
@@ -360,12 +360,12 @@ mod tests {
|
||||
let fetched = s
|
||||
.batch(|tx| {
|
||||
s.create(tx, &job)?;
|
||||
s.finish(tx, job.id, JobState::Failed("peer unreachable".to_string()))?;
|
||||
s.finish(tx, job.id, JobState::Failed { message: "peer unreachable".to_string() })?;
|
||||
s.get(tx, job.id)
|
||||
})
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(fetched.state, JobState::Failed("peer unreachable".to_string()));
|
||||
assert_eq!(fetched.state, JobState::Failed { message: "peer unreachable".to_string() });
|
||||
assert!(fetched.finished_at.is_some());
|
||||
}
|
||||
|
||||
@@ -474,7 +474,10 @@ mod tests {
|
||||
assert_eq!(n, 1);
|
||||
|
||||
let fetched = fetched.unwrap();
|
||||
assert_eq!(fetched.state, JobState::Failed("interrupted by restart".to_string()));
|
||||
assert_eq!(
|
||||
fetched.state,
|
||||
JobState::Failed { message: "interrupted by restart".to_string() }
|
||||
);
|
||||
assert!(fetched.finished_at.is_some());
|
||||
}
|
||||
|
||||
|
||||
@@ -1463,7 +1463,7 @@ fn job_snapshot(
|
||||
.as_ref()
|
||||
.and_then(|id| store.batch(|tx| store.doc_store.get_title(tx, id)).ok().flatten());
|
||||
let error = match &job.state {
|
||||
JobState::Failed(msg) => Some(msg.clone()),
|
||||
JobState::Failed { message } => Some(message.clone()),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
@@ -2037,7 +2037,7 @@ mod job_snapshot_tests {
|
||||
let dir = TempDir::new().unwrap();
|
||||
let store = Store::create(dir.path()).unwrap();
|
||||
let mut job = sample_job(JobKind::Import, JobSubject::Path("a.pdf".to_string()));
|
||||
job.state = JobState::Failed("disk full".to_string());
|
||||
job.state = JobState::Failed { message: "disk full".to_string() };
|
||||
|
||||
let snapshot = job_snapshot(&store, &job, &std::collections::HashMap::new());
|
||||
assert_eq!(snapshot.state, "failed");
|
||||
|
||||
Reference in new issue
Block a user