aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--karlc/src/main.rs13
-rw-r--r--karlcommon/protocol.d.ts6
-rw-r--r--karlcommon/src/protocol.rs10
-rw-r--r--karld/src/condition.rs1
-rw-r--r--karld/src/helper.rs12
-rw-r--r--karld/src/main.rs12
6 files changed, 24 insertions, 30 deletions
diff --git a/karlc/src/main.rs b/karlc/src/main.rs
index 55bb974..501ef3c 100644
--- a/karlc/src/main.rs
+++ b/karlc/src/main.rs
@@ -1,17 +1,14 @@
pub mod client;
pub mod pretty;
+use crate::pretty::fmt_condition;
use chrono::{NaiveDateTime, Utc};
use clap::{Args, Parser, Subcommand};
use client::Client;
-use karlcommon::{
- socket_path, version, ClientboundPacket, Condition, Schedule, ServerboundPacket, Task,
-};
+use karlcommon::{socket_path, version, ClientboundPacket, Schedule, ServerboundPacket, Task};
use log::{error, info};
use std::{os::unix::net::UnixStream, path::PathBuf, process::exit};
-use crate::pretty::fmt_condition;
-
/// CLI interface for karld
#[derive(Parser)]
#[clap(about, author, version)]
@@ -96,7 +93,7 @@ fn main() {
if !t.tags.is_empty() {
println!(" \x1b[38;2;100;255;100mTags:\x1b[0m {}", t.tags.join(", "));
}
- print!(" \x1b[38;2;100;255;100mSchedule: \x1b[0m",);
+ print!(" \x1b[38;2;100;255;100mSchedule: \x1b[0m");
match t.schedule {
Schedule::Never => println!("\x1b[3m\x1b[2m(never)\x1b[0m"),
Schedule::Dynamic { .. } => todo!(),
@@ -122,13 +119,13 @@ fn main() {
for i in instances {
println!(
"\x1b[19G{} - {}",
- i.at.start
+ i.start
.map(|e| format!(
"{}",
NaiveDateTime::from_timestamp(e, 0)
))
.unwrap_or("...".to_string()),
- i.at.end
+ i.end
.map(|e| format!(
"{}",
NaiveDateTime::from_timestamp(e, 0)
diff --git a/karlcommon/protocol.d.ts b/karlcommon/protocol.d.ts
index f48b283..0d93cea 100644
--- a/karlcommon/protocol.d.ts
+++ b/karlcommon/protocol.d.ts
@@ -8,12 +8,10 @@ export interface Handshake { type: "handshake", data: { version: string } }
export interface ListTasks { type: "list_tasks", data: null }
export interface TaskList { type: "task_list", data: Task[] }
export interface ListInstances { type: "list_instances", data: { task: number, range: Range } }
-export interface InstanceList { type: "instance_list", data: Instance[] }
+export interface InstanceList { type: "instance_list", data: Range[] }
export interface UpdateTask { type: "update_task", data: Task }
export interface RemoveTask { type: "remove_task", data: number }
-export interface Instance { of: number, at: Range }
-
export interface Range { start?: number, end?: number }
export interface Task {
@@ -27,7 +25,7 @@ export interface Task {
export type Schedule = { type: "never" }
| { type: "static", options: Range }
| { type: "condition", options: Condition }
- | { type: "dynamic", options: { priority: number, scheduled?: number, deadline?: Condition } }
+ | { type: "dynamic", options: { priority: number, scheduled?: number, deadline?: number } }
export type Condition = { from?: Condition }
| { or?: Condition[] }
diff --git a/karlcommon/src/protocol.rs b/karlcommon/src/protocol.rs
index de65802..25dfc66 100644
--- a/karlcommon/src/protocol.rs
+++ b/karlcommon/src/protocol.rs
@@ -8,7 +8,7 @@ pub enum ClientboundPacket {
Handshake { version: String },
Error(ProtoError),
TaskList(Vec<Task>),
- InstanceList(Vec<Instance>),
+ InstanceList(Vec<Range<Option<i64>>>),
Sync,
}
@@ -52,17 +52,13 @@ pub enum Schedule {
Dynamic {
priority: f64,
scheduled: Option<i64>,
- deadline: Option<Condition>,
+ duration: i64,
+ condition: Condition, // duration, during which the task should be scheduled
},
Condition(Condition),
Static(Range<i64>),
}
-#[derive(Debug, Clone, Serialize, Deserialize)]
-pub struct Instance {
- pub of: u64,
- pub at: Range<Option<i64>>,
-}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
diff --git a/karld/src/condition.rs b/karld/src/condition.rs
index 81f7245..765e039 100644
--- a/karld/src/condition.rs
+++ b/karld/src/condition.rs
@@ -47,6 +47,7 @@ impl ConditionFind for Condition {
match self {
Condition::And(cs) => loop {
// TODO improve efficiency for backward search
+ // TODO fix endless search
let last_start = cs
.iter()
.map(|c| c.find_inverse_inclusive(Start, dir, from))
diff --git a/karld/src/helper.rs b/karld/src/helper.rs
index 2e601b0..f106df6 100644
--- a/karld/src/helper.rs
+++ b/karld/src/helper.rs
@@ -1,5 +1,5 @@
use crate::condition::{ConditionFind, Direction, Edge};
-use chrono::{NaiveDate, NaiveDateTime};
+use chrono::NaiveDateTime;
use karlcommon::{Schedule, Task};
use std::{collections::HashMap, ops::Range};
@@ -34,9 +34,17 @@ impl DiscreteCacheTask {
}
pub fn find(&mut self, from: NaiveDateTime, dir: Direction) -> Range<Option<NaiveDateTime>> {
- assert_eq!(dir, Direction::Forward);
// TODO cache
// if let Some(c) = self.cached {}
+ return self.find_uncached(from, dir);
+ }
+
+ pub fn find_uncached(
+ &mut self,
+ from: NaiveDateTime,
+ dir: Direction,
+ ) -> Range<Option<NaiveDateTime>> {
+ assert_eq!(dir, Direction::Forward); // TODO undefined behaviour if dir is not forward (maybe it even works backward)
match &self.inner.schedule {
Schedule::Condition(o) => {
let start = o.find(Edge::Start, dir, from);
diff --git a/karld/src/main.rs b/karld/src/main.rs
index 181c2be..35cca04 100644
--- a/karld/src/main.rs
+++ b/karld/src/main.rs
@@ -10,7 +10,7 @@ use crossbeam_channel::Sender;
use helper::Overlaps;
use interface::network_loop;
use karlcommon::{
- ClientboundPacket, Condition, Instance, Property, ProtoError, Schedule, ServerboundPacket, Task,
+ ClientboundPacket, Condition, Property, ProtoError, Schedule, ServerboundPacket, Task,
};
use log::{debug, error, info};
use std::{collections::HashMap, sync::RwLock};
@@ -118,10 +118,7 @@ pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender<C
Schedule::Dynamic { .. } => (), // TODO
Schedule::Static(r) => {
if range.overlaps(r.clone()) {
- ocs.push(Instance {
- of: t.id,
- at: Some(r.start)..Some(r.end),
- })
+ ocs.push(Some(r.start)..Some(r.end))
}
}
Schedule::Condition(o) => {
@@ -131,10 +128,7 @@ pub fn handle_packet(client: u32, packet: ServerboundPacket, responder: Sender<C
let start =
o.find(condition::Edge::Start, condition::Direction::Forward, time);
let end = o.find(condition::Edge::End, condition::Direction::Forward, time);
- ocs.push(Instance {
- of: t.id,
- at: start.map(|e| e.timestamp())..end.map(|e| e.timestamp()),
- });
+ ocs.push(start.map(|e| e.timestamp())..end.map(|e| e.timestamp()));
if let Some(s) = end {
if let Some(e) = end_time {
if s > e {