feat: add executor config
This commit is contained in:
parent
9f7c81644d
commit
3e2ec661a1
5 changed files with 96 additions and 17 deletions
|
|
@ -112,11 +112,14 @@ async fn run_task(state: AppState, order: ExecutorOrder) -> Result<()> {
|
|||
cmd.args(task.command.iter().skip(1).collect::<Vec<&String>>())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped());
|
||||
for (key, val) in task.env.iter() {
|
||||
// add OS environment variables from default config and task config
|
||||
for (key, val) in state.config.executor.environment.iter() {
|
||||
cmd.env(key, val);
|
||||
}
|
||||
for (key, val) in task.environment.iter() {
|
||||
cmd.env(key, val);
|
||||
}
|
||||
let status = execute_process(&state, &order, &mut cmd).await?;
|
||||
|
||||
if !status.success() {
|
||||
error!("Non successful exit code found: {}", status);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,9 +83,13 @@ enum ScheduleConfig {
|
|||
#[fully_pub]
|
||||
struct Task {
|
||||
name: String,
|
||||
#[serde(default)]
|
||||
description: Option<String>,
|
||||
env: HashMap<String, String>,
|
||||
/// OS environment to add at runtime
|
||||
#[serde(default)]
|
||||
environment: HashMap<String, String>,
|
||||
command: Vec<String>,
|
||||
#[serde(default)]
|
||||
schedule: Option<ScheduleConfig>
|
||||
}
|
||||
|
||||
|
|
@ -99,11 +103,55 @@ struct ExecutorOrder {
|
|||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[fully_pub]
|
||||
/// branding config of the autotasker
|
||||
struct InstanceConfig {
|
||||
name: String,
|
||||
logo_uri: String
|
||||
}
|
||||
|
||||
#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[serde(untagged)]
|
||||
#[fully_pub]
|
||||
enum LogPolicy {
|
||||
ErrorsOnly,
|
||||
HeadAndTailOnly,
|
||||
#[default]
|
||||
All
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[fully_pub]
|
||||
struct ExecutorConfig {
|
||||
/// the maximum duration of a task run in seconds
|
||||
#[serde(default)]
|
||||
execution_timeout: u64,
|
||||
|
||||
/// the maximum heap memory that a task can allocate in KiloBytes
|
||||
#[serde(default)]
|
||||
max_memory: u64,
|
||||
|
||||
/// the default filter logs policy to apply on a task output
|
||||
#[serde(default)]
|
||||
log_policy: LogPolicy,
|
||||
|
||||
/// default OS environment to add at runtime
|
||||
#[serde(default)]
|
||||
environment: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl Default for ExecutorConfig {
|
||||
fn default() -> ExecutorConfig {
|
||||
ExecutorConfig {
|
||||
execution_timeout: 1000,
|
||||
max_memory: 100_000,
|
||||
log_policy: LogPolicy::All,
|
||||
environment: HashMap::from([
|
||||
("EXECUTOR".into(), "autotasker".into())
|
||||
])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[fully_pub]
|
||||
struct Webhook {
|
||||
|
|
@ -122,9 +170,9 @@ struct Webhook {
|
|||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
|
||||
#[fully_pub]
|
||||
struct Config {
|
||||
instance: InstanceConfig,
|
||||
#[serde(default = "ExecutorConfig::default")]
|
||||
executor: ExecutorConfig,
|
||||
instance: Option<InstanceConfig>,
|
||||
tasks: HashMap<String, Task>,
|
||||
webhooks: Option<Vec<Webhook>>
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue