Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Minimal model

Every model declares the YAML format version and a model name. This model has one entity type, Task, with two events. Events are emitted at most once per entity instance unless the model says otherwise.

YAML model

quent: alpha
model: minimal

entities:
  Task:
    events:
      started: {}
      ended: {}

Instrumentation API

The context provides an observer for each entity type. Calling .handle() on an observer creates a handle for a new entity instance and assigns it a fresh UUID. The handle exposes one method per event.

Every context is created with an exporter, which determines where emitted events go. These examples use the no-op exporter, which discards every event. It keeps the examples focused on the generated API without creating files or starting another service. Applications replace it with an exporter that stores or sends their events.

use instrumentation::{Context, Minimal, Noop, Task};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let context = Context::<Minimal>::try_new(Noop)?;
    let mut task = context.observer::<Task>().handle();

    task.started()?;
    task.ended()?;

    Ok(())
}
#include "quent-tutorial-minimal-model-cpp-bridge/gen/quent.hpp"

int main() {
  auto context = quent::Context::none();
  quent::Handle<quent::Task> task = context.task_observer()->handle();
  task.started();
  task.ended();
  return 0;
}
import quent_tutorial_minimal_model as quent


def main() -> None:
    with quent.Context() as context:
        task = context.task_observer().handle()
        task.started()
        task.ended()


if __name__ == "__main__":
    main()
Key point

The two events have no declared ordering constraint, so either event may be emitted first.

Check yourself

How often can started be emitted for one Task handle?

What does task represent in the application?

Full code