parent
a69a7a46ba
commit
0531cd6693
@ -0,0 +1,75 @@
|
||||
//! Context that is passed to all workers and children
|
||||
|
||||
use super::*;
|
||||
|
||||
use std::sync::{Arc, Weak};
|
||||
use tokio::{
|
||||
sync::{
|
||||
RwLock,
|
||||
mpsc,
|
||||
},
|
||||
task,
|
||||
};
|
||||
|
||||
/// Command to interrupt an `Imouto` worker
|
||||
#[derive(Debug)]
|
||||
pub enum Command {
|
||||
|
||||
}
|
||||
|
||||
/// The child worker for a `Context` interval or target.
|
||||
#[derive(Debug)]
|
||||
pub struct Imouto
|
||||
{
|
||||
parent: Weak<RwLock<InnerContext>>,
|
||||
|
||||
worker: task::JoinHandle<()>,
|
||||
handler: mpsc::Sender<Command>,
|
||||
}
|
||||
|
||||
impl Imouto
|
||||
{
|
||||
/// Get the parent of this worker if it still exists
|
||||
pub fn oneesan(&self) -> Option<Context>
|
||||
{
|
||||
self.parent.upgrade().map(|x| Context(x))
|
||||
}
|
||||
|
||||
/// Is this a zombie worker?
|
||||
pub fn is_orphan(&self) -> bool
|
||||
{
|
||||
self.oneesan().is_none()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
struct InnerContext
|
||||
{
|
||||
/// Name of the job
|
||||
name: String,
|
||||
/// All active child workers for this job
|
||||
children: Vec<Imouto>,
|
||||
|
||||
/// Worker for this context, that updates the children when needed.
|
||||
worker: task::JoinHandle<()>,
|
||||
/// Hook to send `live::Oneesan` events to.
|
||||
live_hook: mpsc::Sender<live::Event>,
|
||||
}
|
||||
|
||||
/// The parent job Context, contains all worker child informations
|
||||
#[derive(Debug)]
|
||||
pub struct Context(Arc<RwLock<InnerContext>>);
|
||||
|
||||
// Job (context::Context)
|
||||
// | -- interval 1 (context::Imouto)
|
||||
// | -- interval 2
|
||||
// \ -- target 1
|
||||
|
||||
// Job 2
|
||||
// \ -- interval
|
||||
|
||||
// Def updated for `Job`:
|
||||
// - Lock the Context
|
||||
// - Update the context
|
||||
// - Interrupt each `Imouto`
|
||||
// - Unlock Context
|
@ -0,0 +1,32 @@
|
||||
//! A single running job
|
||||
use super::*;
|
||||
|
||||
use tokio::{
|
||||
sync::{
|
||||
mpsc,
|
||||
},
|
||||
};
|
||||
|
||||
/// Commands to interrupt jobs
|
||||
#[derive(Debug,PartialEq,Eq,Hash,Clone)]
|
||||
pub enum Command
|
||||
{
|
||||
/// Start graceful shutdown, wait for children.
|
||||
Stop,
|
||||
/// Stop immediately
|
||||
Abort,
|
||||
/// Interrupt the current iteration, and restart the iterator if needed
|
||||
Reseed(interval::Time),
|
||||
/// Run the command now
|
||||
Oneshot,
|
||||
/// Config reload
|
||||
Reload(context::Context),
|
||||
/// Just restart the iterator
|
||||
Restart,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct Job
|
||||
{
|
||||
handler: mpsc::Sender<Command>,
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
//! Live config reloader
|
||||
use super::*;
|
||||
use std::{
|
||||
path::{
|
||||
PathBuf,
|
||||
},
|
||||
};
|
||||
|
||||
/// An event to be passed to `Context`.
|
||||
#[derive(Debug)]
|
||||
pub enum Event
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// A watcher context, we hook specific `Context`s here, to be dispatched to on file change
|
||||
#[derive(Debug)]
|
||||
pub struct Oneesan {
|
||||
path: PathBuf,
|
||||
//TODO: Hooks
|
||||
}
|
||||
|
||||
/// Start watching this path for changes of files
|
||||
pub fn watch(path: PathBuf) -> Oneesan
|
||||
{
|
||||
|
||||
}
|
||||
|
Loading…
Reference in new issue