1use crate::records::{
26 AcknowledgementDisposition, ActionId, Actor, ChargeKey, ChargeMethod, ChargedFilament,
27 ClearedMark, FilePosition, InterventionId, InterventionOutcome, LoadedSpool, PendingCharge,
28 PendingTaken, PolicyDecision, Preflight, PrintAction, PrintOutcome, RecoveryAction,
29 RecoveryRejection, SpoolCommand, SpoolId, SpoolRecord, UnverifiedReason,
30};
31use printobserver_printer_api::{Adjustable, JobSnapshot, PrinterSnapshot, PrinterState};
32use printobserver_supervisor_api::AgentAssessment;
33use printobserver_types::contract::Sample;
34use printobserver_types::schemars::JsonSchema;
35use printobserver_types::serde::{Deserialize, Serialize};
36use printobserver_types::{
37 EventId, EventKind, EventPayload, EventSource, FileName, PrintId, Timestamp,
38};
39
40pub const SYSTEM_SOURCE: &str = "system";
42
43pub const OPERATOR_SOURCE: &str = "operator";
45
46pub const AGENT_SOURCE: &str = "agent";
48
49#[must_use]
51pub fn system_source() -> EventSource {
52 EventSource::new(SYSTEM_SOURCE)
53}
54
55#[must_use]
57pub fn operator_source() -> EventSource {
58 EventSource::new(OPERATOR_SOURCE)
59}
60
61#[must_use]
63pub fn agent_source() -> EventSource {
64 EventSource::new(AGENT_SOURCE)
65}
66
67#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
69#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
70#[schemars(crate = "printobserver_types::schemars")]
71pub struct ActionRequestedPayload {
72 pub action_id: ActionId,
74 pub action: PrintAction,
76 pub actor: Actor,
78}
79
80impl EventPayload for ActionRequestedPayload {
81 const KIND: &'static str = "action_requested";
82}
83
84impl Sample for ActionRequestedPayload {
85 fn sample_full() -> Self {
86 Self {
87 action_id: ActionId::sample_full(),
88 action: PrintAction::sample_full(),
89 actor: Actor::sample_full(),
90 }
91 }
92
93 fn sample_minimal() -> Self {
94 Self {
95 action: PrintAction::sample_minimal(),
96 ..Self::sample_full()
97 }
98 }
99}
100
101#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
103#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
104#[schemars(crate = "printobserver_types::schemars")]
105pub struct ActionExecutedPayload {
106 pub action_id: ActionId,
108 #[serde(default, skip_serializing_if = "Option::is_none")]
110 pub intervention_id: Option<InterventionId>,
111 #[serde(default, skip_serializing_if = "Option::is_none")]
115 pub file_position_bytes: Option<i64>,
116}
117
118impl EventPayload for ActionExecutedPayload {
119 const KIND: &'static str = "action_executed";
120}
121
122impl Sample for ActionExecutedPayload {
123 fn sample_full() -> Self {
124 Self {
125 action_id: ActionId::sample_full(),
126 intervention_id: Some(InterventionId::sample_full()),
127 file_position_bytes: Some(4_096),
128 }
129 }
130
131 fn sample_minimal() -> Self {
132 Self {
133 action_id: ActionId::sample_full(),
134 intervention_id: None,
135 file_position_bytes: None,
136 }
137 }
138}
139
140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
142#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
143#[schemars(crate = "printobserver_types::schemars")]
144pub struct ActionRejectedPayload {
145 pub action_id: ActionId,
147 pub decision: PolicyDecision,
149}
150
151impl EventPayload for ActionRejectedPayload {
152 const KIND: &'static str = "action_rejected";
153}
154
155impl Sample for ActionRejectedPayload {
156 fn sample_full() -> Self {
157 Self {
158 action_id: ActionId::sample_full(),
159 decision: PolicyDecision::sample_full(),
160 }
161 }
162}
163
164#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
166#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
167#[schemars(crate = "printobserver_types::schemars")]
168pub struct InterventionExpiredPayload {
169 pub intervention_id: InterventionId,
171 pub adjustable: Adjustable,
173 pub outcome: InterventionOutcome,
175}
176
177impl EventPayload for InterventionExpiredPayload {
178 const KIND: &'static str = "intervention_expired";
179}
180
181impl Sample for InterventionExpiredPayload {
182 fn sample_full() -> Self {
183 Self {
184 intervention_id: InterventionId::sample_full(),
185 adjustable: Adjustable::Feedrate,
186 outcome: InterventionOutcome::Restored,
187 }
188 }
189}
190
191#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
193#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
194#[schemars(crate = "printobserver_types::schemars")]
195pub struct AgentAssessmentPayload {
196 pub session_name: String,
198 pub assessment: AgentAssessment,
200}
201
202impl EventPayload for AgentAssessmentPayload {
203 const KIND: &'static str = "agent_assessment";
204}
205
206impl Sample for AgentAssessmentPayload {
207 fn sample_full() -> Self {
208 Self {
209 session_name: "print-0191f0a0".to_owned(),
210 assessment: AgentAssessment::sample_full(),
211 }
212 }
213}
214
215#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
217#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
218#[schemars(crate = "printobserver_types::schemars")]
219pub struct OperatorAcknowledgementPayload {
220 pub acknowledged_event_id: EventId,
222 pub disposition: AcknowledgementDisposition,
224}
225
226impl EventPayload for OperatorAcknowledgementPayload {
227 const KIND: &'static str = "operator_acknowledgement";
228}
229
230impl Sample for OperatorAcknowledgementPayload {
231 fn sample_full() -> Self {
232 Self {
233 acknowledged_event_id: EventId::sample_full(),
234 disposition: AcknowledgementDisposition::Watch,
235 }
236 }
237}
238
239#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
249#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
250#[schemars(crate = "printobserver_types::schemars")]
251pub struct CameraLookPayload {
252 pub waited_s: u32,
255 #[serde(default)]
258 pub delivered: Vec<EventId>,
259 #[serde(default, skip_serializing_if = "Option::is_none")]
263 pub frame_captured_at: Option<Timestamp>,
264}
265
266impl EventPayload for CameraLookPayload {
267 const KIND: &'static str = "camera_look";
268}
269
270impl Sample for CameraLookPayload {
271 fn sample_full() -> Self {
272 Self {
273 waited_s: 60,
274 delivered: vec![EventId::sample_full()],
275 frame_captured_at: Some(Timestamp::sample_full()),
276 }
277 }
278
279 fn sample_minimal() -> Self {
280 Self {
281 waited_s: 0,
282 delivered: Vec::new(),
283 frame_captured_at: None,
284 }
285 }
286}
287
288#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
298#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
299#[schemars(crate = "printobserver_types::schemars")]
300pub struct PeriodicObservationPayload {
301 pub interval_s: u64,
303 #[serde(default, skip_serializing_if = "Option::is_none")]
306 pub printer: Option<PrinterSnapshot>,
307 #[serde(default, skip_serializing_if = "Option::is_none")]
310 pub job: Option<JobSnapshot>,
311 #[serde(default, skip_serializing_if = "Option::is_none")]
314 pub frame_captured_at: Option<Timestamp>,
315}
316
317impl EventPayload for PeriodicObservationPayload {
318 const KIND: &'static str = "periodic_observation";
319}
320
321impl Sample for PeriodicObservationPayload {
322 fn sample_full() -> Self {
323 Self {
324 interval_s: 120,
325 printer: Some(PrinterSnapshot::sample_full()),
326 job: Some(JobSnapshot::sample_full()),
327 frame_captured_at: Some(Timestamp::sample_full()),
328 }
329 }
330
331 fn sample_minimal() -> Self {
332 Self {
333 interval_s: 120,
334 printer: None,
335 job: None,
336 frame_captured_at: None,
337 }
338 }
339}
340
341#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
351#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
352#[schemars(crate = "printobserver_types::schemars")]
353pub struct CameraRetryPayload {
354 pub attempt: u32,
356 pub attempts: u32,
358 pub status: u16,
360 pub excerpt: String,
362 pub backoff_ms: u64,
364}
365
366impl EventPayload for CameraRetryPayload {
367 const KIND: &'static str = "camera_retry";
368}
369
370impl Sample for CameraRetryPayload {
371 fn sample_full() -> Self {
372 Self {
373 attempt: 1,
374 attempts: 4,
375 status: 500,
376 excerpt: "exit status 69".to_owned(),
377 backoff_ms: 500,
378 }
379 }
380
381 fn sample_minimal() -> Self {
382 Self {
383 excerpt: String::new(),
384 ..Self::sample_full()
385 }
386 }
387}
388
389#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
391#[serde(
392 crate = "printobserver_types::serde",
393 rename_all = "snake_case",
394 deny_unknown_fields
395)]
396#[schemars(crate = "printobserver_types::schemars")]
397pub enum FrameCause {
398 Blank,
401 Undecodable,
403}
404
405impl Sample for FrameCause {
406 fn sample_full() -> Self {
407 Self::Blank
408 }
409
410 fn sample_alternates() -> Vec<Self> {
411 vec![Self::Undecodable]
412 }
413}
414
415#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
421#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
422#[schemars(crate = "printobserver_types::schemars")]
423pub struct CameraDegradedPayload {
424 pub attempts: u32,
426 pub cause: FrameCause,
428 pub detail: String,
430}
431
432impl EventPayload for CameraDegradedPayload {
433 const KIND: &'static str = "camera_degraded";
434}
435
436impl Sample for CameraDegradedPayload {
437 fn sample_full() -> Self {
438 Self {
439 attempts: 3,
440 cause: FrameCause::Blank,
441 detail: "every frame was near-uniform grey (grey-level spread 2.1 below 36.5)"
442 .to_owned(),
443 }
444 }
445
446 fn sample_alternates() -> Vec<Self> {
447 vec![Self {
448 cause: FrameCause::Undecodable,
449 detail: "every frame failed a strict decode: the image ends early".to_owned(),
450 ..Self::sample_full()
451 }]
452 }
453}
454
455#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
461#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
462#[schemars(crate = "printobserver_types::schemars")]
463pub struct GcodeIndexedPayload {
464 pub file_name: FileName,
466 pub bytes: u64,
468 pub layers: u64,
470}
471
472impl EventPayload for GcodeIndexedPayload {
473 const KIND: &'static str = "gcode_indexed";
474}
475
476impl Sample for GcodeIndexedPayload {
477 fn sample_full() -> Self {
478 Self {
479 file_name: FileName::sample_full(),
480 bytes: 440_608,
481 layers: 150,
482 }
483 }
484}
485
486#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
495#[serde(
496 crate = "printobserver_types::serde",
497 rename_all = "snake_case",
498 deny_unknown_fields
499)]
500#[schemars(crate = "printobserver_types::schemars")]
501pub enum PortFailureSite {
502 PrinterSnapshot,
504 PrinterJob,
506 ImageWrite,
508 SupervisionTurn,
510 CameraLook,
513 DetectorAcknowledgement,
515}
516
517impl Sample for PortFailureSite {
518 fn sample_full() -> Self {
519 Self::PrinterSnapshot
520 }
521}
522
523#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
531#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
532#[schemars(crate = "printobserver_types::schemars")]
533pub struct PortFailurePayload {
534 pub event_id: EventId,
536 pub site: PortFailureSite,
538 pub detail: String,
540}
541
542impl EventPayload for PortFailurePayload {
543 const KIND: &'static str = "port_failure";
544}
545
546impl Sample for PortFailurePayload {
547 fn sample_full() -> Self {
548 Self {
549 event_id: EventId::sample_full(),
550 site: PortFailureSite::sample_full(),
551 detail: "the printer is unreachable: connection refused".to_owned(),
552 }
553 }
554}
555
556pub const TIMELINE_KINDS: [&str; 23] = [
560 PrintStartedPayload::KIND,
561 PrintEndedPayload::KIND,
562 FilamentConsumedPayload::KIND,
563 SpoolRegisteredPayload::KIND,
564 SpoolLoadedPayload::KIND,
565 SpoolUnloadedPayload::KIND,
566 SpoolAdjustedPayload::KIND,
567 SpoolRetiredPayload::KIND,
568 SpoolCommandRejectedPayload::KIND,
569 SpoolUnverifiedPayload::KIND,
570 FilamentChangeSignalledPayload::KIND,
571 UnaccountedPrintPayload::KIND,
572 PreflightCheckedPayload::KIND,
573 ChargePendedPayload::KIND,
574 PrintUntrackedPayload::KIND,
575 FileTallyRebaselinedPayload::KIND,
576 PrinterConnectionChangedPayload::KIND,
577 PrinterResetPayload::KIND,
578 UnattendedPrinterActivityPayload::KIND,
579 DetectorHealthChangedPayload::KIND,
580 RecoveryRequestedPayload::KIND,
581 RecoveryExecutedPayload::KIND,
582 RecoveryRejectedPayload::KIND,
583];
584
585fn sample_spool_id() -> SpoolId {
587 SpoolId::sample_full()
588}
589
590fn sample_reason() -> String {
592 "the spool on the shelf changed".to_owned()
593}
594
595#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
597#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
598#[schemars(crate = "printobserver_types::schemars")]
599pub struct PrintStartedPayload {
600 #[serde(default, skip_serializing_if = "Option::is_none")]
602 pub file_name: Option<String>,
603 #[serde(default, skip_serializing_if = "Option::is_none")]
606 pub started_by: Option<ActionId>,
607 pub loaded: Vec<LoadedSpool>,
609 #[serde(default, skip_serializing_if = "Option::is_none")]
611 pub preflight: Option<Preflight>,
612}
613
614impl EventPayload for PrintStartedPayload {
615 const KIND: &'static str = "print_started";
616}
617
618impl Sample for PrintStartedPayload {
619 fn sample_full() -> Self {
620 Self {
621 file_name: Some("benchy.gcode".to_owned()),
622 started_by: Some(ActionId::sample_full()),
623 loaded: vec![LoadedSpool::sample_full()],
624 preflight: Some(Preflight::sample_full()),
625 }
626 }
627
628 fn sample_minimal() -> Self {
629 Self {
630 file_name: None,
631 started_by: None,
632 loaded: Vec::new(),
633 preflight: None,
634 }
635 }
636}
637
638#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
640#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
641#[schemars(crate = "printobserver_types::schemars")]
642pub struct PrintEndedPayload {
643 pub outcome: PrintOutcome,
645 pub state: PrinterState,
647 pub reason: String,
649 #[serde(default, skip_serializing_if = "Option::is_none")]
651 pub last_position: Option<FilePosition>,
652}
653
654impl EventPayload for PrintEndedPayload {
655 const KIND: &'static str = "print_ended";
656}
657
658impl Sample for PrintEndedPayload {
659 fn sample_full() -> Self {
660 Self {
661 outcome: PrintOutcome::Cancelled,
662 state: PrinterState::Cancelling,
663 reason: "the operator cancelled it".to_owned(),
664 last_position: Some(FilePosition::sample_full()),
665 }
666 }
667
668 fn sample_minimal() -> Self {
669 Self {
670 outcome: PrintOutcome::Completed,
671 state: PrinterState::Operational,
672 reason: "finished".to_owned(),
673 last_position: None,
674 }
675 }
676}
677
678#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
680#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
681#[schemars(crate = "printobserver_types::schemars")]
682pub struct FilamentConsumedPayload {
683 pub charge_key: ChargeKey,
685 pub tool: i64,
687 pub method: ChargeMethod,
689 pub length_mm: f64,
691 #[serde(default, skip_serializing_if = "Option::is_none")]
695 pub charged: Option<ChargedFilament>,
696 #[serde(default, skip_serializing_if = "Option::is_none")]
698 pub analysed_length_mm: Option<f64>,
699 #[serde(default, skip_serializing_if = "Option::is_none")]
701 pub position: Option<FilePosition>,
702 #[serde(default, skip_serializing_if = "Option::is_none")]
704 pub note: Option<String>,
705}
706
707impl EventPayload for FilamentConsumedPayload {
708 const KIND: &'static str = "filament_consumed";
709}
710
711impl Sample for FilamentConsumedPayload {
712 fn sample_full() -> Self {
713 Self {
714 charge_key: ChargeKey::sample_full(),
715 tool: 0,
716 method: ChargeMethod::GcodeExtrusion,
717 length_mm: 1_000.0,
718 charged: Some(ChargedFilament::sample_full()),
719 analysed_length_mm: Some(5_120.0),
720 position: Some(FilePosition::sample_full()),
721 note: Some("charged up to the filament change".to_owned()),
722 }
723 }
724
725 fn sample_minimal() -> Self {
726 Self {
727 charge_key: ChargeKey::sample_full(),
728 tool: 0,
729 method: ChargeMethod::SlicerEstimate,
730 length_mm: 5_120.0,
731 charged: None,
732 analysed_length_mm: None,
733 position: None,
734 note: None,
735 }
736 }
737}
738
739#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
741#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
742#[schemars(crate = "printobserver_types::schemars")]
743pub struct SpoolRegisteredPayload {
744 pub spool: SpoolRecord,
746 pub actor: Actor,
748 pub reason: String,
750}
751
752impl EventPayload for SpoolRegisteredPayload {
753 const KIND: &'static str = "spool_registered";
754}
755
756impl Sample for SpoolRegisteredPayload {
757 fn sample_full() -> Self {
758 Self {
759 spool: SpoolRecord::sample_full(),
760 actor: Actor::Operator,
761 reason: sample_reason(),
762 }
763 }
764
765 fn sample_minimal() -> Self {
766 Self {
767 spool: SpoolRecord::sample_minimal(),
768 ..Self::sample_full()
769 }
770 }
771}
772
773#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
775#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
776#[schemars(crate = "printobserver_types::schemars")]
777pub struct SpoolLoadedPayload {
778 pub spool_id: SpoolId,
780 pub tool: i64,
782 #[serde(default, skip_serializing_if = "Option::is_none")]
784 pub replaced: Option<SpoolId>,
785 #[serde(default, skip_serializing_if = "Vec::is_empty")]
788 pub took_pending: Vec<PendingTaken>,
789 #[serde(default, skip_serializing_if = "Vec::is_empty")]
791 pub cleared_marks: Vec<ClearedMark>,
792 pub actor: Actor,
794 pub reason: String,
796}
797
798impl EventPayload for SpoolLoadedPayload {
799 const KIND: &'static str = "spool_loaded";
800}
801
802impl Sample for SpoolLoadedPayload {
803 fn sample_full() -> Self {
804 Self {
805 spool_id: sample_spool_id(),
806 tool: 0,
807 replaced: Some(ClearedMark::sample_full().spool_id),
808 took_pending: vec![PendingTaken::sample_full()],
809 cleared_marks: vec![ClearedMark::sample_full()],
810 actor: Actor::Operator,
811 reason: sample_reason(),
812 }
813 }
814
815 fn sample_minimal() -> Self {
816 Self {
817 replaced: None,
818 took_pending: Vec::new(),
819 cleared_marks: Vec::new(),
820 ..Self::sample_full()
821 }
822 }
823}
824
825#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
827#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
828#[schemars(crate = "printobserver_types::schemars")]
829pub struct SpoolUnloadedPayload {
830 pub spool_id: SpoolId,
832 pub tool: i64,
834 pub actor: Actor,
836 pub reason: String,
838}
839
840impl EventPayload for SpoolUnloadedPayload {
841 const KIND: &'static str = "spool_unloaded";
842}
843
844impl Sample for SpoolUnloadedPayload {
845 fn sample_full() -> Self {
846 Self {
847 spool_id: sample_spool_id(),
848 tool: 0,
849 actor: Actor::Operator,
850 reason: sample_reason(),
851 }
852 }
853}
854
855#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
857#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
858#[schemars(crate = "printobserver_types::schemars")]
859pub struct SpoolAdjustedPayload {
860 pub spool_id: SpoolId,
862 pub remaining_before_g: f64,
864 pub remaining_after_g: f64,
866 #[serde(default, skip_serializing_if = "Option::is_none")]
869 pub gross_g: Option<f64>,
870 #[serde(default, skip_serializing_if = "Vec::is_empty")]
873 pub took_pending: Vec<PendingTaken>,
874 #[serde(default, skip_serializing_if = "Vec::is_empty")]
876 pub cleared_marks: Vec<ClearedMark>,
877 pub actor: Actor,
879 pub reason: String,
881}
882
883impl EventPayload for SpoolAdjustedPayload {
884 const KIND: &'static str = "spool_adjusted";
885}
886
887impl Sample for SpoolAdjustedPayload {
888 fn sample_full() -> Self {
889 Self {
890 spool_id: sample_spool_id(),
891 remaining_before_g: 742.5,
892 remaining_after_g: 700.0,
893 gross_g: Some(950.0),
894 took_pending: vec![PendingTaken::sample_full()],
895 cleared_marks: vec![ClearedMark {
896 spool_id: sample_spool_id(),
897 reason: UnverifiedReason::sample_full(),
898 }],
899 actor: Actor::Operator,
900 reason: sample_reason(),
901 }
902 }
903
904 fn sample_minimal() -> Self {
905 Self {
906 gross_g: None,
907 took_pending: Vec::new(),
908 cleared_marks: Vec::new(),
909 ..Self::sample_full()
910 }
911 }
912}
913
914#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
916#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
917#[schemars(crate = "printobserver_types::schemars")]
918pub struct SpoolRetiredPayload {
919 pub spool_id: SpoolId,
921 pub remaining_g: f64,
923 pub actor: Actor,
925 pub reason: String,
927}
928
929impl EventPayload for SpoolRetiredPayload {
930 const KIND: &'static str = "spool_retired";
931}
932
933impl Sample for SpoolRetiredPayload {
934 fn sample_full() -> Self {
935 Self {
936 spool_id: sample_spool_id(),
937 remaining_g: 12.5,
938 actor: Actor::Operator,
939 reason: "the spool is empty".to_owned(),
940 }
941 }
942}
943
944#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
946#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
947#[schemars(crate = "printobserver_types::schemars")]
948pub struct SpoolCommandRejectedPayload {
949 pub command: SpoolCommand,
951 pub decision: PolicyDecision,
953}
954
955impl EventPayload for SpoolCommandRejectedPayload {
956 const KIND: &'static str = "spool_command_rejected";
957}
958
959impl Sample for SpoolCommandRejectedPayload {
960 fn sample_full() -> Self {
961 Self {
962 command: SpoolCommand::sample_full(),
963 decision: PolicyDecision::Rejected(crate::records::RejectionReason::SpoolRefused {
964 cause: crate::records::SpoolRefusalCause::DensityRequired {
965 spool_id: None,
966 material: "PEEK".to_owned(),
967 },
968 message: "PEEK has no known density, so the spool needs one".to_owned(),
969 }),
970 }
971 }
972
973 fn sample_minimal() -> Self {
974 Self {
975 command: SpoolCommand::sample_minimal(),
976 ..Self::sample_full()
977 }
978 }
979}
980
981#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
983#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
984#[schemars(crate = "printobserver_types::schemars")]
985pub struct SpoolUnverifiedPayload {
986 pub spool_id: SpoolId,
988 pub reason: UnverifiedReason,
990}
991
992impl EventPayload for SpoolUnverifiedPayload {
993 const KIND: &'static str = "spool_unverified";
994}
995
996impl Sample for SpoolUnverifiedPayload {
997 fn sample_full() -> Self {
998 Self {
999 spool_id: sample_spool_id(),
1000 reason: UnverifiedReason::sample_full(),
1001 }
1002 }
1003}
1004
1005#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1007#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1008#[schemars(crate = "printobserver_types::schemars")]
1009pub struct FilamentChangeSignalledPayload {
1010 #[serde(default, skip_serializing_if = "Option::is_none")]
1012 pub tool: Option<i64>,
1013 #[serde(default, skip_serializing_if = "Option::is_none")]
1015 pub spool_id: Option<SpoolId>,
1016 pub source_kind: EventKind,
1018 #[serde(default, skip_serializing_if = "Option::is_none")]
1021 pub position: Option<SignalPosition>,
1022}
1023
1024#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1026#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1027#[schemars(crate = "printobserver_types::schemars")]
1028pub struct SignalPosition {
1029 pub position: FilePosition,
1031 pub freshness: PositionFreshness,
1034}
1035
1036#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1038#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
1039#[schemars(crate = "printobserver_types::schemars")]
1040pub enum PositionFreshness {
1041 ReadAtSignal,
1043 LastRecorded,
1046}
1047
1048impl EventPayload for FilamentChangeSignalledPayload {
1049 const KIND: &'static str = "filament_change_signalled";
1050}
1051
1052impl Sample for FilamentChangeSignalledPayload {
1053 fn sample_full() -> Self {
1054 Self {
1055 tool: Some(0),
1056 spool_id: Some(sample_spool_id()),
1057 source_kind: EventKind::new("obico_printer_notification").expect("a kind name"),
1058 position: Some(SignalPosition {
1059 position: FilePosition::sample_full(),
1060 freshness: PositionFreshness::ReadAtSignal,
1061 }),
1062 }
1063 }
1064
1065 fn sample_minimal() -> Self {
1066 Self {
1067 tool: None,
1068 spool_id: None,
1069 position: None,
1070 ..Self::sample_full()
1071 }
1072 }
1073}
1074
1075#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1077#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1078#[schemars(crate = "printobserver_types::schemars")]
1079pub struct UnaccountedPrintPayload {
1080 pub file_name: String,
1082 #[serde(default, skip_serializing_if = "Option::is_none")]
1084 pub printed_at: Option<Timestamp>,
1085 pub success: bool,
1088 pub charged: bool,
1091}
1092
1093impl EventPayload for UnaccountedPrintPayload {
1094 const KIND: &'static str = "unaccounted_print";
1095}
1096
1097impl Sample for UnaccountedPrintPayload {
1098 fn sample_full() -> Self {
1099 Self {
1100 file_name: "benchy.gcode".to_owned(),
1101 printed_at: Some(Timestamp::sample_full()),
1102 success: true,
1103 charged: true,
1104 }
1105 }
1106
1107 fn sample_minimal() -> Self {
1108 Self {
1109 printed_at: None,
1110 success: false,
1111 charged: false,
1112 ..Self::sample_full()
1113 }
1114 }
1115}
1116
1117#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1119#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1120#[schemars(crate = "printobserver_types::schemars")]
1121pub struct PreflightCheckedPayload {
1122 pub preflight: Preflight,
1124 #[serde(default, skip_serializing_if = "Option::is_none")]
1126 pub action_id: Option<ActionId>,
1127}
1128
1129impl EventPayload for PreflightCheckedPayload {
1130 const KIND: &'static str = "preflight_checked";
1131}
1132
1133impl Sample for PreflightCheckedPayload {
1134 fn sample_full() -> Self {
1135 Self {
1136 preflight: Preflight::sample_full(),
1137 action_id: Some(ActionId::sample_full()),
1138 }
1139 }
1140
1141 fn sample_minimal() -> Self {
1142 Self {
1143 action_id: None,
1144 ..Self::sample_full()
1145 }
1146 }
1147}
1148
1149#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1152#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1153#[schemars(crate = "printobserver_types::schemars")]
1154pub struct ChargePendedPayload {
1155 pub pending: PendingCharge,
1157}
1158
1159impl EventPayload for ChargePendedPayload {
1160 const KIND: &'static str = "charge_pended";
1161}
1162
1163impl Sample for ChargePendedPayload {
1164 fn sample_full() -> Self {
1165 Self {
1166 pending: PendingCharge::sample_full(),
1167 }
1168 }
1169
1170 fn sample_minimal() -> Self {
1171 Self {
1172 pending: PendingCharge::sample_minimal(),
1173 }
1174 }
1175}
1176
1177#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1180#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1181#[schemars(crate = "printobserver_types::schemars")]
1182pub struct PrintUntrackedPayload {
1183 pub reason: String,
1185}
1186
1187impl EventPayload for PrintUntrackedPayload {
1188 const KIND: &'static str = "print_untracked";
1189}
1190
1191impl Sample for PrintUntrackedPayload {
1192 fn sample_full() -> Self {
1193 Self {
1194 reason: "the print was already running when spool tracking was installed".to_owned(),
1195 }
1196 }
1197}
1198
1199#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1201#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
1202#[schemars(crate = "printobserver_types::schemars")]
1203pub enum RebaselineDisposition {
1204 Accounted,
1206 Unverified,
1209}
1210
1211impl Sample for RebaselineDisposition {
1212 fn sample_full() -> Self {
1213 Self::Unverified
1214 }
1215}
1216
1217#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1223#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1224#[schemars(crate = "printobserver_types::schemars")]
1225pub struct FileTallyRebaselinedPayload {
1226 pub file_name: String,
1228 pub origin: String,
1230 pub old_generation: u32,
1232 pub new_generation: u32,
1234 pub old_successes: i64,
1236 pub old_failures: i64,
1238 pub new_successes: i64,
1240 pub new_failures: i64,
1242 pub disposition: RebaselineDisposition,
1244}
1245
1246impl EventPayload for FileTallyRebaselinedPayload {
1247 const KIND: &'static str = "file_tally_rebaselined";
1248}
1249
1250impl Sample for FileTallyRebaselinedPayload {
1251 fn sample_full() -> Self {
1252 Self {
1253 file_name: "benchy.gcode".to_owned(),
1254 origin: "local".to_owned(),
1255 old_generation: 0,
1256 new_generation: 1,
1257 old_successes: 5,
1258 old_failures: 1,
1259 new_successes: 1,
1260 new_failures: 0,
1261 disposition: RebaselineDisposition::Unverified,
1262 }
1263 }
1264
1265 fn sample_alternates() -> Vec<Self> {
1266 vec![Self {
1267 disposition: RebaselineDisposition::Accounted,
1268 ..Self::sample_full()
1269 }]
1270 }
1271}
1272
1273#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1278#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1279#[schemars(crate = "printobserver_types::schemars")]
1280pub struct PrinterConnectionChangedPayload {
1281 pub from: PrinterState,
1283 pub to: PrinterState,
1285 pub detail: String,
1287}
1288
1289impl EventPayload for PrinterConnectionChangedPayload {
1290 const KIND: &'static str = "printer_connection_changed";
1291}
1292
1293impl Sample for PrinterConnectionChangedPayload {
1294 fn sample_full() -> Self {
1295 Self {
1296 from: PrinterState::Printing,
1297 to: PrinterState::Offline,
1298 detail: "the printer reports Offline after error: SerialTimeoutException: ".to_owned(),
1299 }
1300 }
1301
1302 fn sample_alternates() -> Vec<Self> {
1303 vec![Self {
1304 from: PrinterState::Offline,
1305 to: PrinterState::Operational,
1306 detail: "the printer reports Operational".to_owned(),
1307 }]
1308 }
1309}
1310
1311#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1318#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1319#[schemars(crate = "printobserver_types::schemars")]
1320pub struct PrinterResetPayload {
1321 #[serde(default)]
1323 pub during_print: Option<PrintId>,
1324 pub detail: String,
1326}
1327
1328impl EventPayload for PrinterResetPayload {
1329 const KIND: &'static str = "printer_reset";
1330}
1331
1332impl Sample for PrinterResetPayload {
1333 fn sample_full() -> Self {
1334 Self {
1335 during_print: Some(PrintId::sample_full()),
1336 detail: "the printer pushed a reset".to_owned(),
1337 }
1338 }
1339
1340 fn sample_minimal() -> Self {
1341 Self {
1342 during_print: None,
1343 detail: "the printer pushed a reset".to_owned(),
1344 }
1345 }
1346}
1347
1348#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1350#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1351#[schemars(crate = "printobserver_types::schemars")]
1352pub struct HeatedTool {
1353 pub tool: i64,
1355 pub target_c: f64,
1357}
1358
1359impl Sample for HeatedTool {
1360 fn sample_full() -> Self {
1361 Self {
1362 tool: 0,
1363 target_c: 215.0,
1364 }
1365 }
1366}
1367
1368#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1376#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1377#[schemars(crate = "printobserver_types::schemars")]
1378pub struct UnattendedPrinterActivityPayload {
1379 pub last_print_id: PrintId,
1381 pub tools: Vec<HeatedTool>,
1383 #[serde(default)]
1385 pub bed_target_c: Option<f64>,
1386 #[serde(default)]
1389 pub moved: Option<bool>,
1390 pub detail: String,
1392}
1393
1394impl EventPayload for UnattendedPrinterActivityPayload {
1395 const KIND: &'static str = "unattended_printer_activity";
1396}
1397
1398impl Sample for UnattendedPrinterActivityPayload {
1399 fn sample_full() -> Self {
1400 Self {
1401 last_print_id: PrintId::sample_full(),
1402 tools: vec![HeatedTool::sample_full()],
1403 bed_target_c: Some(60.0),
1404 moved: Some(true),
1405 detail: "tool 0 is heating to 215 °C with no job running".to_owned(),
1406 }
1407 }
1408
1409 fn sample_minimal() -> Self {
1410 Self {
1411 last_print_id: PrintId::sample_full(),
1412 tools: Vec::new(),
1413 bed_target_c: None,
1414 moved: None,
1415 detail: "the print head moved with no job running".to_owned(),
1416 }
1417 }
1418}
1419
1420#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1422#[serde(
1423 crate = "printobserver_types::serde",
1424 rename_all = "snake_case",
1425 deny_unknown_fields
1426)]
1427#[schemars(crate = "printobserver_types::schemars")]
1428pub enum DetectorStatus {
1429 Available,
1431 Unavailable,
1433}
1434
1435impl Sample for DetectorStatus {
1436 fn sample_full() -> Self {
1437 Self::Unavailable
1438 }
1439
1440 fn sample_alternates() -> Vec<Self> {
1441 vec![Self::Available]
1442 }
1443}
1444
1445#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1449#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1450#[schemars(crate = "printobserver_types::schemars")]
1451pub struct DetectorHealthChangedPayload {
1452 pub status: DetectorStatus,
1454 pub detail: String,
1456}
1457
1458impl EventPayload for DetectorHealthChangedPayload {
1459 const KIND: &'static str = "detector_health_changed";
1460}
1461
1462impl Sample for DetectorHealthChangedPayload {
1463 fn sample_full() -> Self {
1464 Self {
1465 status: DetectorStatus::Unavailable,
1466 detail: "the detector's health check answered 503".to_owned(),
1467 }
1468 }
1469
1470 fn sample_alternates() -> Vec<Self> {
1471 vec![Self {
1472 status: DetectorStatus::Available,
1473 detail: "the detector's health check answered 200".to_owned(),
1474 }]
1475 }
1476}
1477
1478#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1482#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1483#[schemars(crate = "printobserver_types::schemars")]
1484pub struct RecoveryRequestedPayload {
1485 pub action: RecoveryAction,
1487 pub actor: Actor,
1489 pub reason: String,
1491}
1492
1493impl EventPayload for RecoveryRequestedPayload {
1494 const KIND: &'static str = "recovery_requested";
1495}
1496
1497impl Sample for RecoveryRequestedPayload {
1498 fn sample_full() -> Self {
1499 Self {
1500 action: RecoveryAction::sample_full(),
1501 actor: Actor::Operator,
1502 reason: "free the nozzle from the part".to_owned(),
1503 }
1504 }
1505}
1506
1507#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1509#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1510#[schemars(crate = "printobserver_types::schemars")]
1511pub struct RecoveryExecutedPayload {
1512 pub action: RecoveryAction,
1514 pub actor: Actor,
1516 pub reason: String,
1518 pub outcome: crate::records::ExecutionOutcome,
1520}
1521
1522impl EventPayload for RecoveryExecutedPayload {
1523 const KIND: &'static str = "recovery_executed";
1524}
1525
1526impl Sample for RecoveryExecutedPayload {
1527 fn sample_full() -> Self {
1528 Self {
1529 action: RecoveryAction::RecoverLift { mm: 10.0 },
1530 actor: Actor::Operator,
1531 reason: "free the nozzle from the part".to_owned(),
1532 outcome: crate::records::ExecutionOutcome::Succeeded,
1533 }
1534 }
1535
1536 fn sample_alternates() -> Vec<Self> {
1537 vec![Self {
1538 outcome: crate::records::ExecutionOutcome::Failed {
1539 reason: "the printer is unreachable: connection refused".to_owned(),
1540 },
1541 ..Self::sample_full()
1542 }]
1543 }
1544}
1545
1546#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1548#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1549#[schemars(crate = "printobserver_types::schemars")]
1550pub struct RecoveryRejectedPayload {
1551 pub action: RecoveryAction,
1553 pub actor: Actor,
1555 pub reason: String,
1557 pub rejection: RecoveryRejection,
1559}
1560
1561impl EventPayload for RecoveryRejectedPayload {
1562 const KIND: &'static str = "recovery_rejected";
1563}
1564
1565impl Sample for RecoveryRejectedPayload {
1566 fn sample_full() -> Self {
1567 Self {
1568 action: RecoveryAction::RecoverPark {
1569 clearance_asserted: false,
1570 },
1571 actor: Actor::Operator,
1572 reason: "move the head off the part".to_owned(),
1573 rejection: RecoveryRejection::sample_full(),
1574 }
1575 }
1576}