Repeated events
Events are once by default. Set multi: true when one entity instance may
emit the same event repeatedly.
YAML model
quent: alpha
model: repeated_events
entities:
Task:
events:
started:
attributes:
command: string
progress:
multi: true
attributes:
items_processed: u64
ended:
attributes:
success: bool
Instrumentation API
The same Task handle emits progress more than once. Repeating started or
ended on that handle would return an error.
use instrumentation::{Context, Noop, RepeatedEvents, Task};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let context = Context::<RepeatedEvents>::try_new(Noop)?;
let mut task = context.observer::<Task>().handle();
task.started("compile".to_owned())?;
// `started` is a once event, so a second call would return an error.
// task.started("compile".to_owned())?;
task.progress(64)?;
task.progress(128)?;
task.ended(true)?;
Ok(())
}
#include "quent-tutorial-repeated-events-cpp-bridge/gen/quent.hpp"
int main() {
auto context = quent::Context::none();
auto task = context.task_observer()->handle();
task.started(quent::task::Started{.command = "compile"});
task.progress(quent::task::Progress{.items_processed = 64});
task.progress(quent::task::Progress{.items_processed = 128});
task.ended(quent::task::Ended{.success = true});
return 0;
}
import quent_tutorial_repeated_events as quent
def main() -> None:
with quent.Context() as context:
task = context.task_observer().handle()
task.started(command="compile")
task.progress(items_processed=64)
task.progress(items_processed=128)
task.ended(success=True)
if __name__ == "__main__":
main()
Key point
multi: true permits an event to be emitted more than once for an entity.