Skip to content

Commit

Permalink
feat: adds alphanumeric name generator
Browse files Browse the repository at this point in the history
  • Loading branch information
claymcleod committed Sep 20, 2024
1 parent 106a12b commit a7ac7be
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions crankshaft-engine/src/service.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Services for various functionality within the execution engine.

pub mod name;
pub mod runner;

pub use runner::Runner;
1 change: 0 additions & 1 deletion crankshaft-engine/src/service/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ impl Runner {
};

self.tasks.push(Box::pin(fun));

TaskHandle { callback: rx }
}

Expand Down
7 changes: 5 additions & 2 deletions crankshaft-engine/src/service/runner/backend/docker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ use futures::stream::FuturesUnordered;
use futures::FutureExt;
use futures::StreamExt;
use nonempty::NonEmpty;
use rand::Rng;
use tempfile::TempDir;

use crate::service::name;
use crate::service::name::Generator;
use crate::service::runner::backend::TaskResult;
use crate::Result;
use crate::Task;
Expand Down Expand Up @@ -120,10 +121,12 @@ fn run(backend: &Backend, task: Task) -> BoxFuture<'static, TaskResult> {
let mut outputs = Vec::new();

for execution in task.executions() {
// NOTE: a name is required by Docker, so a name is generated
// automatically if a name isn't provided.
let name = task
.name()
.map(|v| v.to_owned())
.unwrap_or_else(|| format!("job-{}", rand::thread_rng().gen_range(0..1000000)));
.unwrap_or_else(|| name::Alphanumeric::default().generate());

// (1) Create the container.
let mut builder = client
Expand Down
2 changes: 2 additions & 0 deletions crankshaft-engine/src/service/runner/backend/tes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ impl crate::Backend for Backend {

/// Translates a [`Task`] to a [TES Task](tes::v1::types::Task) for submission.
fn to_tes_task(task: Task) -> tes::v1::types::Task {
// NOTE: a name is not required by the TES specification, so it is kept as
// empty if no name is provided.
let name = task.name().map(|v| v.to_owned());
let description = task.description().map(|v| v.to_owned());

Expand Down

0 comments on commit a7ac7be

Please sign in to comment.