assemble_core/task/work_handler/
input.rs1use crate::__export::{Serializable, TaskId};
2
3use std::time::SystemTime;
4
5#[derive(Deserialize, Serialize, Debug, Clone)]
7pub struct Input {
8 task_id: TaskId,
9 timestamp: SystemTime,
10 serialized_data: Vec<Serializable>,
11}
12
13impl Input {
14 pub fn new<'a>(id: &TaskId, data: Vec<Serializable>) -> Self {
15 let now = SystemTime::now();
16 Self {
17 task_id: id.clone(),
18 timestamp: now,
19 serialized_data: data,
20 }
21 }
22
23 pub fn input_changed(&self, prev: Option<&Input>) -> bool {
25 if let Some(prev) = prev {
26 if self.task_id != prev.task_id {
27 panic!("Cant compare inputs of different tasks");
28 }
29 trace!(
30 "comparing {:#?} to {:#?}",
31 self.serialized_data,
32 prev.serialized_data
33 );
34 let input_data_same = self.serialized_data == prev.serialized_data;
35 !input_data_same
36 } else {
37 true
38 }
39 }
40
41 pub fn any_inputs(&self) -> bool {
43 !self.serialized_data.is_empty()
44 }
45}