Skip to content

Commit

Permalink
Make persistent tasks an optional feature
Browse files Browse the repository at this point in the history
  • Loading branch information
rdaum committed Dec 17, 2024
1 parent d68e7ca commit 311f0d4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
10 changes: 10 additions & 0 deletions crates/daemon/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,13 @@ pub struct FeatureArgs {
help = "Enable flyweight types. Flyweights are a lightweight, object delegate"
)]
pub flyweight_type: Option<bool>,

#[arg(
long,
help = "Enable persistent tasks, which persist the state of suspended/forked tasks between restarts. \
Note that this is the default behaviour in LambdaMOO."
)]
pub persistent_tasks: Option<bool>,
}

impl FeatureArgs {
Expand All @@ -178,6 +185,9 @@ impl FeatureArgs {
if let Some(args) = self.flyweight_type {
config.flyweight_type = args;
}
if let Some(args) = self.persistent_tasks {
config.persistent_tasks = args;
}
}
}
#[derive(Parser, Debug)]
Expand Down
9 changes: 7 additions & 2 deletions crates/daemon/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ use ed25519_dalek::SigningKey;
use eyre::Report;
use moor_db::{Database, TxDB};
use moor_kernel::tasks::scheduler::Scheduler;
use moor_kernel::tasks::{NoopTasksDb, TasksDb};
use moor_kernel::textdump::textdump_load;
use pem::Pem;
use rand::rngs::OsRng;
Expand Down Expand Up @@ -149,7 +150,11 @@ fn main() -> Result<(), Report> {
}
}

let (tasks_db, _) = tasks_fjall::FjallTasksDB::open(&args.tasks_db);
let tasks_db: Box<dyn TasksDb> = if config.features_config.persistent_tasks {
Box::new(tasks_fjall::FjallTasksDB::open(&args.tasks_db).0)
} else {
Box::new(NoopTasksDb {})
};

// We have to create the RpcServer before starting the scheduler because we need to pass it in
// as a parameter to the scheduler for background session construction.
Expand All @@ -173,7 +178,7 @@ fn main() -> Result<(), Report> {
let scheduler = Scheduler::new(
version,
database,
Box::new(tasks_db),
tasks_db,
config.clone(),
rpc_server.clone(),
);
Expand Down
20 changes: 16 additions & 4 deletions crates/kernel/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ pub struct Config {

#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
pub struct FeaturesConfig {
/// Whether to host a tasks DB and persist the state of suspended/forked tasks between restarts.
/// Note that this is the default behaviour in LambdaMOO.
pub persistent_tasks: bool,
/// Whether to allow notify() to send arbitrary MOO common to players. The interpretation of
/// the common varies depending on host/client.
/// If this is false, only strings are allowed, as in LambdaMOO.
Expand All @@ -51,6 +54,7 @@ pub struct FeaturesConfig {
impl Default for FeaturesConfig {
fn default() -> Self {
Self {
persistent_tasks: true,
rich_notify: true,
lexical_scopes: true,
map_type: true,
Expand All @@ -69,16 +73,24 @@ impl FeaturesConfig {
}
}

/// Returns true if the configuration is backwards compatible with LambdaMOO 1.8 features.
/// Returns true if the configuration is backwards compatible with LambdaMOO 1.8 features
pub fn is_lambdammoo_compatible(&self) -> bool {
!self.lexical_scopes && !self.map_type && !self.type_dispatch && !self.flyweight_type
!self.lexical_scopes
&& !self.map_type
&& !self.type_dispatch
&& !self.flyweight_type
&& !self.rich_notify
&& self.persistent_tasks
}

/// Returns true if the configuration is compatible with another configuration.
/// Returns true if the configuration is compatible with another configuration, for the pur
/// poses of textdump loading
/// Which means that if the other configuration has a feature enabled, this configuration
/// must also have it enabled.
/// The other way around is fine.
pub fn is_compatible(&self, other: &FeaturesConfig) -> bool {
pub fn is_textdump_compatible(&self, other: &FeaturesConfig) -> bool {
// Note that tasks/rich_notify are not included in this check, as they do not affect
// the database format.
(!other.lexical_scopes || self.lexical_scopes)
&& (!other.map_type || self.map_type)
&& (!other.type_dispatch || self.type_dispatch)
Expand Down
2 changes: 1 addition & 1 deletion crates/kernel/src/textdump/load_textdump.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ pub fn read_textdump<T: io::Read>(
}

// Features mut be compatible
if !features_config.is_compatible(features) {
if !features_config.is_textdump_compatible(features) {
return Err(TextdumpReaderError::VersionError(
"Incompatible features".to_string(),
));
Expand Down

0 comments on commit 311f0d4

Please sign in to comment.