read method
Looks at the node and reports what is there.
Never throws for "it is not there" — that is
ResourceState with absent. Throwing is for "I could not look", and the
planner turns it into ResourceState.unknown rather than letting it fail
the whole plan: one unreadable resource should not blind the other thirty.
Implementation
@override
Future<ResourceState> read(
ResolvedResource resource,
FormulaContext context,
) async {
final formula = registry.byId(resource.id.name);
if (formula == null) {
// Not absent. This node has never heard of the formula, which says
// nothing about whether the software is on the machine — and reporting
// `absent` would invite an install this node cannot perform anyway.
return ResourceState.unknown(
resource.id,
context.now(),
message: 'this node has no formula "${resource.id.name}"',
);
}
final report = await formula.status(context);
return ResourceState(
id: resource.id,
status: report.status,
version: report.version,
message: report.message,
// The detected version is the fingerprint: for a formula, "the same" means
// the same version, and there is nothing else to compare.
fingerprint: report.version,
checkedAt: report.checkedAt,
);
}