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::{
|
use crate::{
|
||||||
message::{
|
message::{
|
||||||
action::MsgAction,
|
action::{Action, MsgAction},
|
||||||
wrapper::{Message, Records},
|
wrapper::{Message, Records},
|
||||||
},
|
},
|
||||||
name::{Name, NameType, Names},
|
name::{Name, NameType, Names},
|
||||||
queue::{
|
queue::{
|
||||||
data_director::{RegMsg, Register},
|
data_director::{Include, Path, RegMsg, Register},
|
||||||
router::Queue,
|
router::Queue,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
@ -24,11 +24,27 @@ impl Clock {
|
|||||||
Self { queue: queue }
|
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) {
|
pub fn start(mut queue: Queue) {
|
||||||
let clock = Clock::new(queue.clone());
|
let clock = Clock::new(queue.clone());
|
||||||
let (tx, rx) = channel();
|
let (tx, rx) = channel();
|
||||||
let id = queue.add_sender(tx);
|
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());
|
let msg = Message::new(NameType::None, reg_msg.clone());
|
||||||
queue.send(msg);
|
queue.send(msg);
|
||||||
rx.recv().unwrap();
|
rx.recv().unwrap();
|
||||||
@ -39,15 +55,21 @@ impl Clock {
|
|||||||
|
|
||||||
fn listen(&self) {
|
fn listen(&self) {
|
||||||
loop {
|
loop {
|
||||||
self.queue.send(Message::new(
|
self.queue.send(Clock::gen_message());
|
||||||
Name::english("clock"),
|
|
||||||
MsgAction::OnUpdate(Records::new(Names::new())),
|
|
||||||
));
|
|
||||||
sleep(Duration::from_secs(1));
|
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)]
|
#[cfg(test)]
|
||||||
mod clocks {
|
mod clocks {
|
||||||
use super::*;
|
use super::*;
|
||||||
@ -76,7 +98,7 @@ mod clocks {
|
|||||||
let end = Utc::now();
|
let end = Utc::now();
|
||||||
assert!((end - start) > TimeDelta::seconds(1));
|
assert!((end - start) > TimeDelta::seconds(1));
|
||||||
assert!((end - start) < TimeDelta::seconds(2));
|
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));
|
queue.send(Message::new(NameType::None, reg_request));
|
||||||
rx.recv_timeout(TIMEOUT).unwrap();
|
rx.recv_timeout(TIMEOUT).unwrap();
|
||||||
for msg in holder.iter() {
|
for msg in holder.iter() {
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
use crate::{
|
use crate::{
|
||||||
document::{
|
document::{
|
||||||
|
clock::Clock,
|
||||||
create::IndexType,
|
create::IndexType,
|
||||||
definition::{DocDef, DocFuncType},
|
definition::{DocDef, DocFuncType},
|
||||||
field::FieldType,
|
field::FieldType,
|
||||||
@ -40,6 +41,7 @@ impl Session {
|
|||||||
let name_expire = Name::english("expire");
|
let name_expire = Name::english("expire");
|
||||||
docdef.add_field(name_expire.clone(), FieldType::DateTime);
|
docdef.add_field(name_expire.clone(), FieldType::DateTime);
|
||||||
docdef.set_default(&name_expire, calc.clone()).unwrap();
|
docdef.set_default(&name_expire, calc.clone()).unwrap();
|
||||||
|
docdef.add_index(&name_expire, IndexType::Index).unwrap();
|
||||||
|
|
||||||
let mut update = Update::new(Query::new());
|
let mut update = Update::new(Query::new());
|
||||||
update
|
update
|
||||||
@ -61,13 +63,8 @@ impl Session {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
delete_qry.add(name_expire.clone(), delete_calc);
|
delete_qry.add(name_expire.clone(), delete_calc);
|
||||||
let delete = Delete::new(delete_qry);
|
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());
|
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 (tx, rx) = channel();
|
||||||
let sender_id = queue.add_sender(tx);
|
let sender_id = queue.add_sender(tx);
|
||||||
@ -91,7 +88,7 @@ impl Session {
|
|||||||
mod sessions {
|
mod sessions {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::{
|
use crate::{
|
||||||
document::{clock::Clock, create::CreateDoc, field::Field},
|
document::{clock::{Clock, clock_test_support::gen_clock_message}, create::CreateDoc, field::Field},
|
||||||
message::{
|
message::{
|
||||||
action::MsgAction,
|
action::MsgAction,
|
||||||
wrapper::{Addition, Query, Records},
|
wrapper::{Addition, Query, Records},
|
||||||
@ -328,10 +325,7 @@ mod sessions {
|
|||||||
setup.send(Setup::message(addition2));
|
setup.send(Setup::message(addition2));
|
||||||
setup.recv().unwrap(); // Eat addition result.
|
setup.recv().unwrap(); // Eat addition result.
|
||||||
setup.recv().unwrap(); // Eat addition result.
|
setup.recv().unwrap(); // Eat addition result.
|
||||||
setup.send(Message::new(
|
setup.send(gen_clock_message());
|
||||||
Name::english("clock"),
|
|
||||||
MsgAction::OnUpdate(Records::new(Names::new())),
|
|
||||||
));
|
|
||||||
sleep(TIMEOUT); // Allow time to react to message.
|
sleep(TIMEOUT); // Allow time to react to message.
|
||||||
setup.send(Setup::message(Query::new()));
|
setup.send(Setup::message(Query::new()));
|
||||||
let result = setup.recv().unwrap();
|
let result = setup.recv().unwrap();
|
||||||
|
|||||||
@ -12,204 +12,6 @@ use std::{
|
|||||||
};
|
};
|
||||||
use uuid::Uuid;
|
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)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Message {
|
pub struct Message {
|
||||||
msg_id: Uuid,
|
msg_id: Uuid,
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user