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::{EventId, EventKind, EventPayload, EventSource, PrintId, Timestamp};
37
38pub const SYSTEM_SOURCE: &str = "system";
40
41pub const OPERATOR_SOURCE: &str = "operator";
43
44pub const AGENT_SOURCE: &str = "agent";
46
47#[must_use]
49pub fn system_source() -> EventSource {
50 EventSource::new(SYSTEM_SOURCE)
51}
52
53#[must_use]
55pub fn operator_source() -> EventSource {
56 EventSource::new(OPERATOR_SOURCE)
57}
58
59#[must_use]
61pub fn agent_source() -> EventSource {
62 EventSource::new(AGENT_SOURCE)
63}
64
65#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
67#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
68#[schemars(crate = "printobserver_types::schemars")]
69pub struct ActionRequestedPayload {
70 pub action_id: ActionId,
72 pub action: PrintAction,
74 pub actor: Actor,
76}
77
78impl EventPayload for ActionRequestedPayload {
79 const KIND: &'static str = "action_requested";
80}
81
82impl Sample for ActionRequestedPayload {
83 fn sample_full() -> Self {
84 Self {
85 action_id: ActionId::sample_full(),
86 action: PrintAction::sample_full(),
87 actor: Actor::sample_full(),
88 }
89 }
90
91 fn sample_minimal() -> Self {
92 Self {
93 action: PrintAction::sample_minimal(),
94 ..Self::sample_full()
95 }
96 }
97}
98
99#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
101#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
102#[schemars(crate = "printobserver_types::schemars")]
103pub struct ActionExecutedPayload {
104 pub action_id: ActionId,
106 #[serde(default, skip_serializing_if = "Option::is_none")]
108 pub intervention_id: Option<InterventionId>,
109}
110
111impl EventPayload for ActionExecutedPayload {
112 const KIND: &'static str = "action_executed";
113}
114
115impl Sample for ActionExecutedPayload {
116 fn sample_full() -> Self {
117 Self {
118 action_id: ActionId::sample_full(),
119 intervention_id: Some(InterventionId::sample_full()),
120 }
121 }
122
123 fn sample_minimal() -> Self {
124 Self {
125 action_id: ActionId::sample_full(),
126 intervention_id: None,
127 }
128 }
129}
130
131#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
133#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
134#[schemars(crate = "printobserver_types::schemars")]
135pub struct ActionRejectedPayload {
136 pub action_id: ActionId,
138 pub decision: PolicyDecision,
140}
141
142impl EventPayload for ActionRejectedPayload {
143 const KIND: &'static str = "action_rejected";
144}
145
146impl Sample for ActionRejectedPayload {
147 fn sample_full() -> Self {
148 Self {
149 action_id: ActionId::sample_full(),
150 decision: PolicyDecision::sample_full(),
151 }
152 }
153}
154
155#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
157#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
158#[schemars(crate = "printobserver_types::schemars")]
159pub struct InterventionExpiredPayload {
160 pub intervention_id: InterventionId,
162 pub adjustable: Adjustable,
164 pub outcome: InterventionOutcome,
166}
167
168impl EventPayload for InterventionExpiredPayload {
169 const KIND: &'static str = "intervention_expired";
170}
171
172impl Sample for InterventionExpiredPayload {
173 fn sample_full() -> Self {
174 Self {
175 intervention_id: InterventionId::sample_full(),
176 adjustable: Adjustable::Feedrate,
177 outcome: InterventionOutcome::Restored,
178 }
179 }
180}
181
182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
184#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
185#[schemars(crate = "printobserver_types::schemars")]
186pub struct AgentAssessmentPayload {
187 pub session_name: String,
189 pub assessment: AgentAssessment,
191}
192
193impl EventPayload for AgentAssessmentPayload {
194 const KIND: &'static str = "agent_assessment";
195}
196
197impl Sample for AgentAssessmentPayload {
198 fn sample_full() -> Self {
199 Self {
200 session_name: "print-0191f0a0".to_owned(),
201 assessment: AgentAssessment::sample_full(),
202 }
203 }
204}
205
206#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
208#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
209#[schemars(crate = "printobserver_types::schemars")]
210pub struct OperatorAcknowledgementPayload {
211 pub acknowledged_event_id: EventId,
213 pub disposition: AcknowledgementDisposition,
215}
216
217impl EventPayload for OperatorAcknowledgementPayload {
218 const KIND: &'static str = "operator_acknowledgement";
219}
220
221impl Sample for OperatorAcknowledgementPayload {
222 fn sample_full() -> Self {
223 Self {
224 acknowledged_event_id: EventId::sample_full(),
225 disposition: AcknowledgementDisposition::Watch,
226 }
227 }
228}
229
230#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
240#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
241#[schemars(crate = "printobserver_types::schemars")]
242pub struct CameraLookPayload {
243 pub waited_s: u32,
246 #[serde(default)]
249 pub delivered: Vec<EventId>,
250 #[serde(default, skip_serializing_if = "Option::is_none")]
254 pub frame_captured_at: Option<Timestamp>,
255}
256
257impl EventPayload for CameraLookPayload {
258 const KIND: &'static str = "camera_look";
259}
260
261impl Sample for CameraLookPayload {
262 fn sample_full() -> Self {
263 Self {
264 waited_s: 60,
265 delivered: vec![EventId::sample_full()],
266 frame_captured_at: Some(Timestamp::sample_full()),
267 }
268 }
269
270 fn sample_minimal() -> Self {
271 Self {
272 waited_s: 0,
273 delivered: Vec::new(),
274 frame_captured_at: None,
275 }
276 }
277}
278
279#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
289#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
290#[schemars(crate = "printobserver_types::schemars")]
291pub struct PeriodicObservationPayload {
292 pub interval_s: u64,
294 #[serde(default, skip_serializing_if = "Option::is_none")]
297 pub printer: Option<PrinterSnapshot>,
298 #[serde(default, skip_serializing_if = "Option::is_none")]
301 pub job: Option<JobSnapshot>,
302 #[serde(default, skip_serializing_if = "Option::is_none")]
305 pub frame_captured_at: Option<Timestamp>,
306}
307
308impl EventPayload for PeriodicObservationPayload {
309 const KIND: &'static str = "periodic_observation";
310}
311
312impl Sample for PeriodicObservationPayload {
313 fn sample_full() -> Self {
314 Self {
315 interval_s: 120,
316 printer: Some(PrinterSnapshot::sample_full()),
317 job: Some(JobSnapshot::sample_full()),
318 frame_captured_at: Some(Timestamp::sample_full()),
319 }
320 }
321
322 fn sample_minimal() -> Self {
323 Self {
324 interval_s: 120,
325 printer: None,
326 job: None,
327 frame_captured_at: None,
328 }
329 }
330}
331
332#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
342#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
343#[schemars(crate = "printobserver_types::schemars")]
344pub struct CameraRetryPayload {
345 pub attempt: u32,
347 pub attempts: u32,
349 pub status: u16,
351 pub excerpt: String,
353 pub backoff_ms: u64,
355}
356
357impl EventPayload for CameraRetryPayload {
358 const KIND: &'static str = "camera_retry";
359}
360
361impl Sample for CameraRetryPayload {
362 fn sample_full() -> Self {
363 Self {
364 attempt: 1,
365 attempts: 4,
366 status: 500,
367 excerpt: "exit status 69".to_owned(),
368 backoff_ms: 500,
369 }
370 }
371
372 fn sample_minimal() -> Self {
373 Self {
374 excerpt: String::new(),
375 ..Self::sample_full()
376 }
377 }
378}
379
380#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
382#[serde(
383 crate = "printobserver_types::serde",
384 rename_all = "snake_case",
385 deny_unknown_fields
386)]
387#[schemars(crate = "printobserver_types::schemars")]
388pub enum FrameCause {
389 Blank,
392 Undecodable,
394}
395
396impl Sample for FrameCause {
397 fn sample_full() -> Self {
398 Self::Blank
399 }
400
401 fn sample_alternates() -> Vec<Self> {
402 vec![Self::Undecodable]
403 }
404}
405
406#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
412#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
413#[schemars(crate = "printobserver_types::schemars")]
414pub struct CameraDegradedPayload {
415 pub attempts: u32,
417 pub cause: FrameCause,
419 pub detail: String,
421}
422
423impl EventPayload for CameraDegradedPayload {
424 const KIND: &'static str = "camera_degraded";
425}
426
427impl Sample for CameraDegradedPayload {
428 fn sample_full() -> Self {
429 Self {
430 attempts: 3,
431 cause: FrameCause::Blank,
432 detail: "every frame was near-uniform grey (grey-level spread 2.1 below 36.5)"
433 .to_owned(),
434 }
435 }
436
437 fn sample_alternates() -> Vec<Self> {
438 vec![Self {
439 cause: FrameCause::Undecodable,
440 detail: "every frame failed a strict decode: the image ends early".to_owned(),
441 ..Self::sample_full()
442 }]
443 }
444}
445
446#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
455#[serde(
456 crate = "printobserver_types::serde",
457 rename_all = "snake_case",
458 deny_unknown_fields
459)]
460#[schemars(crate = "printobserver_types::schemars")]
461pub enum PortFailureSite {
462 PrinterSnapshot,
464 PrinterJob,
466 ImageWrite,
468 SupervisionTurn,
470 CameraLook,
473 DetectorAcknowledgement,
475}
476
477impl Sample for PortFailureSite {
478 fn sample_full() -> Self {
479 Self::PrinterSnapshot
480 }
481}
482
483#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
491#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
492#[schemars(crate = "printobserver_types::schemars")]
493pub struct PortFailurePayload {
494 pub event_id: EventId,
496 pub site: PortFailureSite,
498 pub detail: String,
500}
501
502impl EventPayload for PortFailurePayload {
503 const KIND: &'static str = "port_failure";
504}
505
506impl Sample for PortFailurePayload {
507 fn sample_full() -> Self {
508 Self {
509 event_id: EventId::sample_full(),
510 site: PortFailureSite::sample_full(),
511 detail: "the printer is unreachable: connection refused".to_owned(),
512 }
513 }
514}
515
516pub const TIMELINE_KINDS: [&str; 23] = [
520 PrintStartedPayload::KIND,
521 PrintEndedPayload::KIND,
522 FilamentConsumedPayload::KIND,
523 SpoolRegisteredPayload::KIND,
524 SpoolLoadedPayload::KIND,
525 SpoolUnloadedPayload::KIND,
526 SpoolAdjustedPayload::KIND,
527 SpoolRetiredPayload::KIND,
528 SpoolCommandRejectedPayload::KIND,
529 SpoolUnverifiedPayload::KIND,
530 FilamentChangeSignalledPayload::KIND,
531 UnaccountedPrintPayload::KIND,
532 PreflightCheckedPayload::KIND,
533 ChargePendedPayload::KIND,
534 PrintUntrackedPayload::KIND,
535 FileTallyRebaselinedPayload::KIND,
536 PrinterConnectionChangedPayload::KIND,
537 PrinterResetPayload::KIND,
538 UnattendedPrinterActivityPayload::KIND,
539 DetectorHealthChangedPayload::KIND,
540 RecoveryRequestedPayload::KIND,
541 RecoveryExecutedPayload::KIND,
542 RecoveryRejectedPayload::KIND,
543];
544
545fn sample_spool_id() -> SpoolId {
547 SpoolId::sample_full()
548}
549
550fn sample_reason() -> String {
552 "the spool on the shelf changed".to_owned()
553}
554
555#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
557#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
558#[schemars(crate = "printobserver_types::schemars")]
559pub struct PrintStartedPayload {
560 #[serde(default, skip_serializing_if = "Option::is_none")]
562 pub file_name: Option<String>,
563 #[serde(default, skip_serializing_if = "Option::is_none")]
566 pub started_by: Option<ActionId>,
567 pub loaded: Vec<LoadedSpool>,
569 #[serde(default, skip_serializing_if = "Option::is_none")]
571 pub preflight: Option<Preflight>,
572}
573
574impl EventPayload for PrintStartedPayload {
575 const KIND: &'static str = "print_started";
576}
577
578impl Sample for PrintStartedPayload {
579 fn sample_full() -> Self {
580 Self {
581 file_name: Some("benchy.gcode".to_owned()),
582 started_by: Some(ActionId::sample_full()),
583 loaded: vec![LoadedSpool::sample_full()],
584 preflight: Some(Preflight::sample_full()),
585 }
586 }
587
588 fn sample_minimal() -> Self {
589 Self {
590 file_name: None,
591 started_by: None,
592 loaded: Vec::new(),
593 preflight: None,
594 }
595 }
596}
597
598#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
600#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
601#[schemars(crate = "printobserver_types::schemars")]
602pub struct PrintEndedPayload {
603 pub outcome: PrintOutcome,
605 pub state: PrinterState,
607 pub reason: String,
609 #[serde(default, skip_serializing_if = "Option::is_none")]
611 pub last_position: Option<FilePosition>,
612}
613
614impl EventPayload for PrintEndedPayload {
615 const KIND: &'static str = "print_ended";
616}
617
618impl Sample for PrintEndedPayload {
619 fn sample_full() -> Self {
620 Self {
621 outcome: PrintOutcome::Cancelled,
622 state: PrinterState::Cancelling,
623 reason: "the operator cancelled it".to_owned(),
624 last_position: Some(FilePosition::sample_full()),
625 }
626 }
627
628 fn sample_minimal() -> Self {
629 Self {
630 outcome: PrintOutcome::Completed,
631 state: PrinterState::Operational,
632 reason: "finished".to_owned(),
633 last_position: 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 FilamentConsumedPayload {
643 pub charge_key: ChargeKey,
645 pub tool: i64,
647 pub method: ChargeMethod,
649 pub length_mm: f64,
651 #[serde(default, skip_serializing_if = "Option::is_none")]
655 pub charged: Option<ChargedFilament>,
656 #[serde(default, skip_serializing_if = "Option::is_none")]
658 pub analysed_length_mm: Option<f64>,
659 #[serde(default, skip_serializing_if = "Option::is_none")]
661 pub position: Option<FilePosition>,
662 #[serde(default, skip_serializing_if = "Option::is_none")]
664 pub note: Option<String>,
665}
666
667impl EventPayload for FilamentConsumedPayload {
668 const KIND: &'static str = "filament_consumed";
669}
670
671impl Sample for FilamentConsumedPayload {
672 fn sample_full() -> Self {
673 Self {
674 charge_key: ChargeKey::sample_full(),
675 tool: 0,
676 method: ChargeMethod::GcodeExtrusion,
677 length_mm: 1_000.0,
678 charged: Some(ChargedFilament::sample_full()),
679 analysed_length_mm: Some(5_120.0),
680 position: Some(FilePosition::sample_full()),
681 note: Some("charged up to the filament change".to_owned()),
682 }
683 }
684
685 fn sample_minimal() -> Self {
686 Self {
687 charge_key: ChargeKey::sample_full(),
688 tool: 0,
689 method: ChargeMethod::SlicerEstimate,
690 length_mm: 5_120.0,
691 charged: None,
692 analysed_length_mm: None,
693 position: None,
694 note: None,
695 }
696 }
697}
698
699#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
701#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
702#[schemars(crate = "printobserver_types::schemars")]
703pub struct SpoolRegisteredPayload {
704 pub spool: SpoolRecord,
706 pub actor: Actor,
708 pub reason: String,
710}
711
712impl EventPayload for SpoolRegisteredPayload {
713 const KIND: &'static str = "spool_registered";
714}
715
716impl Sample for SpoolRegisteredPayload {
717 fn sample_full() -> Self {
718 Self {
719 spool: SpoolRecord::sample_full(),
720 actor: Actor::Operator,
721 reason: sample_reason(),
722 }
723 }
724
725 fn sample_minimal() -> Self {
726 Self {
727 spool: SpoolRecord::sample_minimal(),
728 ..Self::sample_full()
729 }
730 }
731}
732
733#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
735#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
736#[schemars(crate = "printobserver_types::schemars")]
737pub struct SpoolLoadedPayload {
738 pub spool_id: SpoolId,
740 pub tool: i64,
742 #[serde(default, skip_serializing_if = "Option::is_none")]
744 pub replaced: Option<SpoolId>,
745 #[serde(default, skip_serializing_if = "Vec::is_empty")]
748 pub took_pending: Vec<PendingTaken>,
749 #[serde(default, skip_serializing_if = "Vec::is_empty")]
751 pub cleared_marks: Vec<ClearedMark>,
752 pub actor: Actor,
754 pub reason: String,
756}
757
758impl EventPayload for SpoolLoadedPayload {
759 const KIND: &'static str = "spool_loaded";
760}
761
762impl Sample for SpoolLoadedPayload {
763 fn sample_full() -> Self {
764 Self {
765 spool_id: sample_spool_id(),
766 tool: 0,
767 replaced: Some(ClearedMark::sample_full().spool_id),
768 took_pending: vec![PendingTaken::sample_full()],
769 cleared_marks: vec![ClearedMark::sample_full()],
770 actor: Actor::Operator,
771 reason: sample_reason(),
772 }
773 }
774
775 fn sample_minimal() -> Self {
776 Self {
777 replaced: None,
778 took_pending: Vec::new(),
779 cleared_marks: Vec::new(),
780 ..Self::sample_full()
781 }
782 }
783}
784
785#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
787#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
788#[schemars(crate = "printobserver_types::schemars")]
789pub struct SpoolUnloadedPayload {
790 pub spool_id: SpoolId,
792 pub tool: i64,
794 pub actor: Actor,
796 pub reason: String,
798}
799
800impl EventPayload for SpoolUnloadedPayload {
801 const KIND: &'static str = "spool_unloaded";
802}
803
804impl Sample for SpoolUnloadedPayload {
805 fn sample_full() -> Self {
806 Self {
807 spool_id: sample_spool_id(),
808 tool: 0,
809 actor: Actor::Operator,
810 reason: sample_reason(),
811 }
812 }
813}
814
815#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
817#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
818#[schemars(crate = "printobserver_types::schemars")]
819pub struct SpoolAdjustedPayload {
820 pub spool_id: SpoolId,
822 pub remaining_before_g: f64,
824 pub remaining_after_g: f64,
826 #[serde(default, skip_serializing_if = "Option::is_none")]
829 pub gross_g: Option<f64>,
830 #[serde(default, skip_serializing_if = "Vec::is_empty")]
833 pub took_pending: Vec<PendingTaken>,
834 #[serde(default, skip_serializing_if = "Vec::is_empty")]
836 pub cleared_marks: Vec<ClearedMark>,
837 pub actor: Actor,
839 pub reason: String,
841}
842
843impl EventPayload for SpoolAdjustedPayload {
844 const KIND: &'static str = "spool_adjusted";
845}
846
847impl Sample for SpoolAdjustedPayload {
848 fn sample_full() -> Self {
849 Self {
850 spool_id: sample_spool_id(),
851 remaining_before_g: 742.5,
852 remaining_after_g: 700.0,
853 gross_g: Some(950.0),
854 took_pending: vec![PendingTaken::sample_full()],
855 cleared_marks: vec![ClearedMark {
856 spool_id: sample_spool_id(),
857 reason: UnverifiedReason::sample_full(),
858 }],
859 actor: Actor::Operator,
860 reason: sample_reason(),
861 }
862 }
863
864 fn sample_minimal() -> Self {
865 Self {
866 gross_g: None,
867 took_pending: Vec::new(),
868 cleared_marks: Vec::new(),
869 ..Self::sample_full()
870 }
871 }
872}
873
874#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
876#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
877#[schemars(crate = "printobserver_types::schemars")]
878pub struct SpoolRetiredPayload {
879 pub spool_id: SpoolId,
881 pub remaining_g: f64,
883 pub actor: Actor,
885 pub reason: String,
887}
888
889impl EventPayload for SpoolRetiredPayload {
890 const KIND: &'static str = "spool_retired";
891}
892
893impl Sample for SpoolRetiredPayload {
894 fn sample_full() -> Self {
895 Self {
896 spool_id: sample_spool_id(),
897 remaining_g: 12.5,
898 actor: Actor::Operator,
899 reason: "the spool is empty".to_owned(),
900 }
901 }
902}
903
904#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
906#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
907#[schemars(crate = "printobserver_types::schemars")]
908pub struct SpoolCommandRejectedPayload {
909 pub command: SpoolCommand,
911 pub decision: PolicyDecision,
913}
914
915impl EventPayload for SpoolCommandRejectedPayload {
916 const KIND: &'static str = "spool_command_rejected";
917}
918
919impl Sample for SpoolCommandRejectedPayload {
920 fn sample_full() -> Self {
921 Self {
922 command: SpoolCommand::sample_full(),
923 decision: PolicyDecision::Rejected(crate::records::RejectionReason::SpoolRefused {
924 cause: crate::records::SpoolRefusalCause::DensityRequired {
925 spool_id: None,
926 material: "PEEK".to_owned(),
927 },
928 message: "PEEK has no known density, so the spool needs one".to_owned(),
929 }),
930 }
931 }
932
933 fn sample_minimal() -> Self {
934 Self {
935 command: SpoolCommand::sample_minimal(),
936 ..Self::sample_full()
937 }
938 }
939}
940
941#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
943#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
944#[schemars(crate = "printobserver_types::schemars")]
945pub struct SpoolUnverifiedPayload {
946 pub spool_id: SpoolId,
948 pub reason: UnverifiedReason,
950}
951
952impl EventPayload for SpoolUnverifiedPayload {
953 const KIND: &'static str = "spool_unverified";
954}
955
956impl Sample for SpoolUnverifiedPayload {
957 fn sample_full() -> Self {
958 Self {
959 spool_id: sample_spool_id(),
960 reason: UnverifiedReason::sample_full(),
961 }
962 }
963}
964
965#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
967#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
968#[schemars(crate = "printobserver_types::schemars")]
969pub struct FilamentChangeSignalledPayload {
970 #[serde(default, skip_serializing_if = "Option::is_none")]
972 pub tool: Option<i64>,
973 #[serde(default, skip_serializing_if = "Option::is_none")]
975 pub spool_id: Option<SpoolId>,
976 pub source_kind: EventKind,
978 #[serde(default, skip_serializing_if = "Option::is_none")]
981 pub position: Option<SignalPosition>,
982}
983
984#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
986#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
987#[schemars(crate = "printobserver_types::schemars")]
988pub struct SignalPosition {
989 pub position: FilePosition,
991 pub freshness: PositionFreshness,
994}
995
996#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
998#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
999#[schemars(crate = "printobserver_types::schemars")]
1000pub enum PositionFreshness {
1001 ReadAtSignal,
1003 LastRecorded,
1006}
1007
1008impl EventPayload for FilamentChangeSignalledPayload {
1009 const KIND: &'static str = "filament_change_signalled";
1010}
1011
1012impl Sample for FilamentChangeSignalledPayload {
1013 fn sample_full() -> Self {
1014 Self {
1015 tool: Some(0),
1016 spool_id: Some(sample_spool_id()),
1017 source_kind: EventKind::new("obico_printer_notification").expect("a kind name"),
1018 position: Some(SignalPosition {
1019 position: FilePosition::sample_full(),
1020 freshness: PositionFreshness::ReadAtSignal,
1021 }),
1022 }
1023 }
1024
1025 fn sample_minimal() -> Self {
1026 Self {
1027 tool: None,
1028 spool_id: None,
1029 position: None,
1030 ..Self::sample_full()
1031 }
1032 }
1033}
1034
1035#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1037#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1038#[schemars(crate = "printobserver_types::schemars")]
1039pub struct UnaccountedPrintPayload {
1040 pub file_name: String,
1042 #[serde(default, skip_serializing_if = "Option::is_none")]
1044 pub printed_at: Option<Timestamp>,
1045 pub success: bool,
1048 pub charged: bool,
1051}
1052
1053impl EventPayload for UnaccountedPrintPayload {
1054 const KIND: &'static str = "unaccounted_print";
1055}
1056
1057impl Sample for UnaccountedPrintPayload {
1058 fn sample_full() -> Self {
1059 Self {
1060 file_name: "benchy.gcode".to_owned(),
1061 printed_at: Some(Timestamp::sample_full()),
1062 success: true,
1063 charged: true,
1064 }
1065 }
1066
1067 fn sample_minimal() -> Self {
1068 Self {
1069 printed_at: None,
1070 success: false,
1071 charged: false,
1072 ..Self::sample_full()
1073 }
1074 }
1075}
1076
1077#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1079#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1080#[schemars(crate = "printobserver_types::schemars")]
1081pub struct PreflightCheckedPayload {
1082 pub preflight: Preflight,
1084 #[serde(default, skip_serializing_if = "Option::is_none")]
1086 pub action_id: Option<ActionId>,
1087}
1088
1089impl EventPayload for PreflightCheckedPayload {
1090 const KIND: &'static str = "preflight_checked";
1091}
1092
1093impl Sample for PreflightCheckedPayload {
1094 fn sample_full() -> Self {
1095 Self {
1096 preflight: Preflight::sample_full(),
1097 action_id: Some(ActionId::sample_full()),
1098 }
1099 }
1100
1101 fn sample_minimal() -> Self {
1102 Self {
1103 action_id: None,
1104 ..Self::sample_full()
1105 }
1106 }
1107}
1108
1109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1112#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1113#[schemars(crate = "printobserver_types::schemars")]
1114pub struct ChargePendedPayload {
1115 pub pending: PendingCharge,
1117}
1118
1119impl EventPayload for ChargePendedPayload {
1120 const KIND: &'static str = "charge_pended";
1121}
1122
1123impl Sample for ChargePendedPayload {
1124 fn sample_full() -> Self {
1125 Self {
1126 pending: PendingCharge::sample_full(),
1127 }
1128 }
1129
1130 fn sample_minimal() -> Self {
1131 Self {
1132 pending: PendingCharge::sample_minimal(),
1133 }
1134 }
1135}
1136
1137#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1140#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1141#[schemars(crate = "printobserver_types::schemars")]
1142pub struct PrintUntrackedPayload {
1143 pub reason: String,
1145}
1146
1147impl EventPayload for PrintUntrackedPayload {
1148 const KIND: &'static str = "print_untracked";
1149}
1150
1151impl Sample for PrintUntrackedPayload {
1152 fn sample_full() -> Self {
1153 Self {
1154 reason: "the print was already running when spool tracking was installed".to_owned(),
1155 }
1156 }
1157}
1158
1159#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1161#[serde(crate = "printobserver_types::serde", rename_all = "snake_case")]
1162#[schemars(crate = "printobserver_types::schemars")]
1163pub enum RebaselineDisposition {
1164 Accounted,
1166 Unverified,
1169}
1170
1171impl Sample for RebaselineDisposition {
1172 fn sample_full() -> Self {
1173 Self::Unverified
1174 }
1175}
1176
1177#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1183#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1184#[schemars(crate = "printobserver_types::schemars")]
1185pub struct FileTallyRebaselinedPayload {
1186 pub file_name: String,
1188 pub origin: String,
1190 pub old_generation: u32,
1192 pub new_generation: u32,
1194 pub old_successes: i64,
1196 pub old_failures: i64,
1198 pub new_successes: i64,
1200 pub new_failures: i64,
1202 pub disposition: RebaselineDisposition,
1204}
1205
1206impl EventPayload for FileTallyRebaselinedPayload {
1207 const KIND: &'static str = "file_tally_rebaselined";
1208}
1209
1210impl Sample for FileTallyRebaselinedPayload {
1211 fn sample_full() -> Self {
1212 Self {
1213 file_name: "benchy.gcode".to_owned(),
1214 origin: "local".to_owned(),
1215 old_generation: 0,
1216 new_generation: 1,
1217 old_successes: 5,
1218 old_failures: 1,
1219 new_successes: 1,
1220 new_failures: 0,
1221 disposition: RebaselineDisposition::Unverified,
1222 }
1223 }
1224
1225 fn sample_alternates() -> Vec<Self> {
1226 vec![Self {
1227 disposition: RebaselineDisposition::Accounted,
1228 ..Self::sample_full()
1229 }]
1230 }
1231}
1232
1233#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1238#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1239#[schemars(crate = "printobserver_types::schemars")]
1240pub struct PrinterConnectionChangedPayload {
1241 pub from: PrinterState,
1243 pub to: PrinterState,
1245 pub detail: String,
1247}
1248
1249impl EventPayload for PrinterConnectionChangedPayload {
1250 const KIND: &'static str = "printer_connection_changed";
1251}
1252
1253impl Sample for PrinterConnectionChangedPayload {
1254 fn sample_full() -> Self {
1255 Self {
1256 from: PrinterState::Printing,
1257 to: PrinterState::Offline,
1258 detail: "the printer reports Offline after error: SerialTimeoutException: ".to_owned(),
1259 }
1260 }
1261
1262 fn sample_alternates() -> Vec<Self> {
1263 vec![Self {
1264 from: PrinterState::Offline,
1265 to: PrinterState::Operational,
1266 detail: "the printer reports Operational".to_owned(),
1267 }]
1268 }
1269}
1270
1271#[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 PrinterResetPayload {
1281 #[serde(default)]
1283 pub during_print: Option<PrintId>,
1284 pub detail: String,
1286}
1287
1288impl EventPayload for PrinterResetPayload {
1289 const KIND: &'static str = "printer_reset";
1290}
1291
1292impl Sample for PrinterResetPayload {
1293 fn sample_full() -> Self {
1294 Self {
1295 during_print: Some(PrintId::sample_full()),
1296 detail: "the printer pushed a reset".to_owned(),
1297 }
1298 }
1299
1300 fn sample_minimal() -> Self {
1301 Self {
1302 during_print: None,
1303 detail: "the printer pushed a reset".to_owned(),
1304 }
1305 }
1306}
1307
1308#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1310#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1311#[schemars(crate = "printobserver_types::schemars")]
1312pub struct HeatedTool {
1313 pub tool: i64,
1315 pub target_c: f64,
1317}
1318
1319impl Sample for HeatedTool {
1320 fn sample_full() -> Self {
1321 Self {
1322 tool: 0,
1323 target_c: 215.0,
1324 }
1325 }
1326}
1327
1328#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1336#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1337#[schemars(crate = "printobserver_types::schemars")]
1338pub struct UnattendedPrinterActivityPayload {
1339 pub last_print_id: PrintId,
1341 pub tools: Vec<HeatedTool>,
1343 #[serde(default)]
1345 pub bed_target_c: Option<f64>,
1346 #[serde(default)]
1349 pub moved: Option<bool>,
1350 pub detail: String,
1352}
1353
1354impl EventPayload for UnattendedPrinterActivityPayload {
1355 const KIND: &'static str = "unattended_printer_activity";
1356}
1357
1358impl Sample for UnattendedPrinterActivityPayload {
1359 fn sample_full() -> Self {
1360 Self {
1361 last_print_id: PrintId::sample_full(),
1362 tools: vec![HeatedTool::sample_full()],
1363 bed_target_c: Some(60.0),
1364 moved: Some(true),
1365 detail: "tool 0 is heating to 215 °C with no job running".to_owned(),
1366 }
1367 }
1368
1369 fn sample_minimal() -> Self {
1370 Self {
1371 last_print_id: PrintId::sample_full(),
1372 tools: Vec::new(),
1373 bed_target_c: None,
1374 moved: None,
1375 detail: "the print head moved with no job running".to_owned(),
1376 }
1377 }
1378}
1379
1380#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1382#[serde(
1383 crate = "printobserver_types::serde",
1384 rename_all = "snake_case",
1385 deny_unknown_fields
1386)]
1387#[schemars(crate = "printobserver_types::schemars")]
1388pub enum DetectorStatus {
1389 Available,
1391 Unavailable,
1393}
1394
1395impl Sample for DetectorStatus {
1396 fn sample_full() -> Self {
1397 Self::Unavailable
1398 }
1399
1400 fn sample_alternates() -> Vec<Self> {
1401 vec![Self::Available]
1402 }
1403}
1404
1405#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema)]
1409#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1410#[schemars(crate = "printobserver_types::schemars")]
1411pub struct DetectorHealthChangedPayload {
1412 pub status: DetectorStatus,
1414 pub detail: String,
1416}
1417
1418impl EventPayload for DetectorHealthChangedPayload {
1419 const KIND: &'static str = "detector_health_changed";
1420}
1421
1422impl Sample for DetectorHealthChangedPayload {
1423 fn sample_full() -> Self {
1424 Self {
1425 status: DetectorStatus::Unavailable,
1426 detail: "the detector's health check answered 503".to_owned(),
1427 }
1428 }
1429
1430 fn sample_alternates() -> Vec<Self> {
1431 vec![Self {
1432 status: DetectorStatus::Available,
1433 detail: "the detector's health check answered 200".to_owned(),
1434 }]
1435 }
1436}
1437
1438#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1442#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1443#[schemars(crate = "printobserver_types::schemars")]
1444pub struct RecoveryRequestedPayload {
1445 pub action: RecoveryAction,
1447 pub actor: Actor,
1449 pub reason: String,
1451}
1452
1453impl EventPayload for RecoveryRequestedPayload {
1454 const KIND: &'static str = "recovery_requested";
1455}
1456
1457impl Sample for RecoveryRequestedPayload {
1458 fn sample_full() -> Self {
1459 Self {
1460 action: RecoveryAction::sample_full(),
1461 actor: Actor::Operator,
1462 reason: "free the nozzle from the part".to_owned(),
1463 }
1464 }
1465}
1466
1467#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1469#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1470#[schemars(crate = "printobserver_types::schemars")]
1471pub struct RecoveryExecutedPayload {
1472 pub action: RecoveryAction,
1474 pub actor: Actor,
1476 pub reason: String,
1478 pub outcome: crate::records::ExecutionOutcome,
1480}
1481
1482impl EventPayload for RecoveryExecutedPayload {
1483 const KIND: &'static str = "recovery_executed";
1484}
1485
1486impl Sample for RecoveryExecutedPayload {
1487 fn sample_full() -> Self {
1488 Self {
1489 action: RecoveryAction::RecoverLift { mm: 10.0 },
1490 actor: Actor::Operator,
1491 reason: "free the nozzle from the part".to_owned(),
1492 outcome: crate::records::ExecutionOutcome::Succeeded,
1493 }
1494 }
1495
1496 fn sample_alternates() -> Vec<Self> {
1497 vec![Self {
1498 outcome: crate::records::ExecutionOutcome::Failed {
1499 reason: "the printer is unreachable: connection refused".to_owned(),
1500 },
1501 ..Self::sample_full()
1502 }]
1503 }
1504}
1505
1506#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, JsonSchema)]
1508#[serde(crate = "printobserver_types::serde", deny_unknown_fields)]
1509#[schemars(crate = "printobserver_types::schemars")]
1510pub struct RecoveryRejectedPayload {
1511 pub action: RecoveryAction,
1513 pub actor: Actor,
1515 pub reason: String,
1517 pub rejection: RecoveryRejection,
1519}
1520
1521impl EventPayload for RecoveryRejectedPayload {
1522 const KIND: &'static str = "recovery_rejected";
1523}
1524
1525impl Sample for RecoveryRejectedPayload {
1526 fn sample_full() -> Self {
1527 Self {
1528 action: RecoveryAction::RecoverPark {
1529 clearance_asserted: false,
1530 },
1531 actor: Actor::Operator,
1532 reason: "move the head off the part".to_owned(),
1533 rejection: RecoveryRejection::sample_full(),
1534 }
1535 }
1536}