Refactored clock.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
use crate::{
|
||||
message::{
|
||||
action::MsgAction,
|
||||
action::{Action, MsgAction},
|
||||
wrapper::{Message, Records},
|
||||
},
|
||||
name::{Name, NameType, Names},
|
||||
queue::{
|
||||
data_director::{RegMsg, Register},
|
||||
data_director::{Include, Path, RegMsg, Register},
|
||||
router::Queue,
|
||||
},
|
||||
};
|
||||
@@ -24,11 +24,27 @@ impl Clock {
|
||||
Self { queue: queue }
|
||||
}
|
||||
|
||||
fn get_name() -> Name {
|
||||
Name::english("clock")
|
||||
}
|
||||
|
||||
fn gen_message() -> Message {
|
||||
Message::new(Clock::get_name(), MsgAction::OnUpdate(Records::new(Names::new())))
|
||||
}
|
||||
|
||||
pub fn get_path() -> Path {
|
||||
Path::new(
|
||||
Include::All,
|
||||
Include::Just(Clock::get_name().into()),
|
||||
Include::Just(Action::OnUpdate),
|
||||
)
|
||||
}
|
||||
|
||||
pub fn start(mut queue: Queue) {
|
||||
let clock = Clock::new(queue.clone());
|
||||
let (tx, rx) = channel();
|
||||
let id = queue.add_sender(tx);
|
||||
let reg_msg = Register::new(id, RegMsg::AddDocName([Name::english("clock")].to_vec()));
|
||||
let reg_msg = Register::new(id, RegMsg::AddDocName([Clock::get_name()].to_vec()));
|
||||
let msg = Message::new(NameType::None, reg_msg.clone());
|
||||
queue.send(msg);
|
||||
rx.recv().unwrap();
|
||||
@@ -39,15 +55,21 @@ impl Clock {
|
||||
|
||||
fn listen(&self) {
|
||||
loop {
|
||||
self.queue.send(Message::new(
|
||||
Name::english("clock"),
|
||||
MsgAction::OnUpdate(Records::new(Names::new())),
|
||||
));
|
||||
self.queue.send(Clock::gen_message());
|
||||
sleep(Duration::from_secs(1));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod clock_test_support {
|
||||
use super::*;
|
||||
|
||||
pub fn gen_clock_message() -> Message {
|
||||
Clock::gen_message()
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod clocks {
|
||||
use super::*;
|
||||
@@ -76,7 +98,7 @@ mod clocks {
|
||||
let end = Utc::now();
|
||||
assert!((end - start) > TimeDelta::seconds(1));
|
||||
assert!((end - start) < TimeDelta::seconds(2));
|
||||
let reg_request = Register::new(id, RegMsg::GetNameID(Name::english("clock")));
|
||||
let reg_request = Register::new(id, RegMsg::GetNameID(Clock::get_name()));
|
||||
queue.send(Message::new(NameType::None, reg_request));
|
||||
rx.recv_timeout(TIMEOUT).unwrap();
|
||||
for msg in holder.iter() {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::{
|
||||
document::{
|
||||
clock::Clock,
|
||||
create::IndexType,
|
||||
definition::{DocDef, DocFuncType},
|
||||
field::FieldType,
|
||||
@@ -40,6 +41,7 @@ impl Session {
|
||||
let name_expire = Name::english("expire");
|
||||
docdef.add_field(name_expire.clone(), FieldType::DateTime);
|
||||
docdef.set_default(&name_expire, calc.clone()).unwrap();
|
||||
docdef.add_index(&name_expire, IndexType::Index).unwrap();
|
||||
|
||||
let mut update = Update::new(Query::new());
|
||||
update
|
||||
@@ -61,13 +63,8 @@ impl Session {
|
||||
.unwrap();
|
||||
delete_qry.add(name_expire.clone(), delete_calc);
|
||||
let delete = Delete::new(delete_qry);
|
||||
let clock_path = Path::new(
|
||||
Include::All,
|
||||
Include::Just(Name::english("clock").into()),
|
||||
Include::Just(Action::OnUpdate),
|
||||
);
|
||||
let delete_func = DocFuncType::Trigger(delete.into());
|
||||
docdef.add_route(clock_path, delete_func);
|
||||
docdef.add_route(Clock::get_path(), delete_func);
|
||||
|
||||
let (tx, rx) = channel();
|
||||
let sender_id = queue.add_sender(tx);
|
||||
@@ -91,7 +88,7 @@ impl Session {
|
||||
mod sessions {
|
||||
use super::*;
|
||||
use crate::{
|
||||
document::{clock::Clock, create::CreateDoc, field::Field},
|
||||
document::{clock::{Clock, clock_test_support::gen_clock_message}, create::CreateDoc, field::Field},
|
||||
message::{
|
||||
action::MsgAction,
|
||||
wrapper::{Addition, Query, Records},
|
||||
@@ -328,10 +325,7 @@ mod sessions {
|
||||
setup.send(Setup::message(addition2));
|
||||
setup.recv().unwrap(); // Eat addition result.
|
||||
setup.recv().unwrap(); // Eat addition result.
|
||||
setup.send(Message::new(
|
||||
Name::english("clock"),
|
||||
MsgAction::OnUpdate(Records::new(Names::new())),
|
||||
));
|
||||
setup.send(gen_clock_message());
|
||||
sleep(TIMEOUT); // Allow time to react to message.
|
||||
setup.send(Setup::message(Query::new()));
|
||||
let result = setup.recv().unwrap();
|
||||
|
||||
Reference in New Issue
Block a user