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:
parent
0dbf75d0c6
commit
57ee7dd6ae
@ -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();
|
||||
|
||||
@ -12,204 +12,6 @@ use std::{
|
||||
};
|
||||
use uuid::Uuid;
|
||||
|
||||
/*
|
||||
#[derive(Clone, Debug, Eq, Hash, PartialEq)]
|
||||
pub enum Action {
|
||||
Addition,
|
||||
Create,
|
||||
Delete,
|
||||
Error,
|
||||
GetLog,
|
||||
Log,
|
||||
OnAddition,
|
||||
OnDelete,
|
||||
OnQuery,
|
||||
OnUpdate,
|
||||
Query,
|
||||
Records,
|
||||
Register,
|
||||
Reply,
|
||||
Show,
|
||||
Update,
|
||||
}
|
||||
|
||||
impl From<MsgAction> for Action {
|
||||
fn from(value: MsgAction) -> Self {
|
||||
match value {
|
||||
MsgAction::Addition(_) => Action::Addition,
|
||||
MsgAction::Create(_) => Action::Create,
|
||||
MsgAction::Delete(_) => Action::Delete,
|
||||
MsgAction::Error(_) => Action::Error,
|
||||
MsgAction::GetLog(_) => Action::GetLog,
|
||||
MsgAction::OnAddition(_) => Action::OnAddition,
|
||||
MsgAction::OnDelete(_) => Action::OnDelete,
|
||||
MsgAction::OnQuery(_) => Action::OnQuery,
|
||||
MsgAction::OnUpdate(_) => Action::OnUpdate,
|
||||
MsgAction::Query(_) => Action::Query,
|
||||
MsgAction::Records(_) => Action::Records,
|
||||
MsgAction::Register(_) => Action::Register,
|
||||
MsgAction::Reply(_) => Action::Reply,
|
||||
MsgAction::Show => Action::Show,
|
||||
MsgAction::Update(_) => Action::Update,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&MsgAction> for Action {
|
||||
fn from(value: &MsgAction) -> Self {
|
||||
let action = value.clone();
|
||||
Self::from(action)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum MsgAction {
|
||||
Addition(Addition),
|
||||
Create(DocDef),
|
||||
// Alter
|
||||
// Remove
|
||||
Error(MTTError),
|
||||
GetLog(Uuid),
|
||||
OnAddition(Records),
|
||||
OnDelete(Records),
|
||||
OnQuery(Records),
|
||||
OnUpdate(Records),
|
||||
Query(Query),
|
||||
Records(Records),
|
||||
Register(Register),
|
||||
Reply(Reply),
|
||||
Show,
|
||||
Delete(Delete),
|
||||
Update(Update),
|
||||
}
|
||||
|
||||
impl From<Addition> for MsgAction {
|
||||
fn from(value: Addition) -> Self {
|
||||
MsgAction::Addition(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Delete> for MsgAction {
|
||||
fn from(value: Delete) -> Self {
|
||||
MsgAction::Delete(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<DocDef> for MsgAction {
|
||||
fn from(value: DocDef) -> Self {
|
||||
MsgAction::Create(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<MTTError> for MsgAction {
|
||||
fn from(value: MTTError) -> Self {
|
||||
MsgAction::Error(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Query> for MsgAction {
|
||||
fn from(value: Query) -> Self {
|
||||
MsgAction::Query(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Records> for MsgAction {
|
||||
fn from(value: Records) -> Self {
|
||||
MsgAction::Records(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Register> for MsgAction {
|
||||
fn from(value: Register) -> Self {
|
||||
MsgAction::Register(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Reply> for MsgAction {
|
||||
fn from(value: Reply) -> Self {
|
||||
MsgAction::Reply(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Update> for MsgAction {
|
||||
fn from(value: Update) -> Self {
|
||||
MsgAction::Update(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Uuid> for MsgAction {
|
||||
fn from(value: Uuid) -> Self {
|
||||
MsgAction::GetLog(value)
|
||||
}
|
||||
}
|
||||
|
||||
impl From<&Uuid> for MsgAction {
|
||||
fn from(value: &Uuid) -> Self {
|
||||
Self::from(value.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod msgactions {
|
||||
use super::*;
|
||||
use crate::name::Name;
|
||||
|
||||
#[test]
|
||||
fn turn_document_definition_into_action() {
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let value = DocDef::new(name.clone());
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Create(def) => assert_eq!(def.get_document_names(), &[name].to_vec()),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_error_into_action() {
|
||||
let data = "data".to_string();
|
||||
let value = MTTError::DocumentAlreadyExists(data.clone());
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Error(result) => match result {
|
||||
MTTError::DocumentAlreadyExists(output) => assert_eq!(output, data),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
},
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
let value = MTTError::DocumentNotFound(data.clone());
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Error(result) => match result {
|
||||
MTTError::DocumentNotFound(output) => assert_eq!(output, data),
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
},
|
||||
_ => unreachable!("Got {:?}: dhould have been create", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_query_into_action() {
|
||||
let value = Query::new();
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Query(_) => {}
|
||||
_ => unreachable!("Got {:?}: dhould have been query", result),
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn turn_reply_into_action() {
|
||||
let value = Reply::new();
|
||||
let result: MsgAction = value.into();
|
||||
match result {
|
||||
MsgAction::Reply(_) => {}
|
||||
_ => unreachable!("Got {:?}: dhould have been reply", result),
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Message {
|
||||
msg_id: Uuid,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user