Struct foxbox_thinkerbell::manager::ScriptManager [] [src]

pub struct ScriptManager<Env, T> where Env: ExecutableDevEnv + Clone + 'static {
    // some fields omitted
}

ScriptManager stores a persistent database of scripts and executes them. Each script can be individually enabled or disabled. When a script is enabled, it is always running (unless an error occured during launch). Script sources are stored as JSON strings in a SQLite database.

Methods

impl<Env, T> ScriptManager<Env, T> where Env: ExecutableDevEnv + Clone + 'static, T: ExtSender<(Id<ScriptId>, ExecutionEvent)> + TransformableSender<(Id<ScriptId>, ExecutionEvent)>

fn new(env: Env, path: &FilePath, tx: Box<T>) -> Result<Self, Error>

Create a ScriptManager using a SQLite database file with the given path, i.e. filename. If the database file does not exist, it will be created.

NOTE: You MUST consume the contents of tx to prevent memory leaks.

The database stores the raw script source, but only after the source has been parsed to ensure validity.

fn load(&mut self) -> Result<ResultMap<Id<ScriptId>, (), Error>, Error>

Load and launch all existing scripts from the database.

fn put(&mut self, id: &Id<ScriptId>, source: &String) -> Result<(), Error>

Attempt to add a new script. The script will be executed and persisted to disk. The ID is chosen by the consumer and must be unique.

fn set_enabled(&mut self, id: &Id<ScriptId>, enabled: bool) -> Result<(), Error>

Enable or disable a script, starting or stopping the script if necessary.

fn remove(&mut self, id: &Id<ScriptId>) -> Result<(), Error>

Remove a script entirely, stopping it if necessary. If the script cannot be stopped (due to an error), it will not be removed.

fn remove_all(&mut self) -> Result<Vec<Error>, Error>

Remove all scripts, stopping any running scripts. (If any scripts fail to stop, we store and return those errors in a Vec so that we ensure that the database always gets wiped.)

fn get_running_count(&self) -> usize

Get the number of currently-running scripts.

fn get_source(&self, id: &Id<ScriptId>) -> Result<String, Error>

Get the source for a script with the given id.

fn is_enabled(&self, id: &Id<ScriptId>) -> bool

Return true if the script is enabled.