Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 14 additions & 33 deletions components/spider-core/src/types/id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ use serde::{Deserialize, Serialize};
use sqlx::{Database, encode::IsNull};
use uuid::Uuid;

use crate::task::TaskIndex;

/// A generic identifier type that wraps a UUID and a type marker.
///
/// # Type Parameters:
Expand Down Expand Up @@ -96,9 +98,18 @@ pub type UuidBytes = uuid::Bytes;
pub enum ResourceGroupIdMarker {}
pub type ResourceGroupId = Id<ResourceGroupIdMarker>;

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TaskIdMarker {}
pub type TaskId = Id<TaskIdMarker>;
/// Identifier of a task inside a job.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum TaskId {
/// The index of the task in the job's task graph.
Index(TaskIndex),

/// The commit task.
Commit,

/// The cleanup task.
Cleanup,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum JobIdMarker {}
Expand Down Expand Up @@ -169,33 +180,3 @@ where
}

pub type SignedJobId = SignedId<JobIdMarker>;

pub type SignedTaskId = SignedId<TaskIdMarker>;

#[cfg(test)]
mod tests {
use std::any::TypeId;

use super::*;

#[test]
fn test_id_basic() {
let id = TaskId::new();
let underlying_uuid = id.as_uuid_ref().to_owned();
assert_eq!(id, TaskId::from(underlying_uuid));

assert_ne!(TypeId::of::<TaskId>(), TypeId::of::<JobId>());
}

#[test]
fn task_id_json_roundtrip() {
let id = TaskId::new();
let deserialized_id: TaskId = serde_json::from_str(
serde_json::to_string(&id)
.expect("JSON serialization failure")
.as_str(),
)
.expect("JSON deserialization failure");
assert_eq!(id, deserialized_id);
}
}
15 changes: 0 additions & 15 deletions components/spider-storage/src/cache.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
use spider_core::task::TaskIndex;

pub mod error;
pub mod io;
pub mod job;
pub mod job_submission;
mod sync;
pub mod task;

/// Identifier of a task inside a job.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum TaskId {
/// The index of the task in the job's task graph.
Index(TaskIndex),

/// The commit task.
Commit,

/// The cleanup task.
Cleanup,
}
3 changes: 1 addition & 2 deletions components/spider-storage/src/cache/job.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ use spider_core::{
job::JobState,
task::{TaskIndex, TaskState},
types::{
id::{ExecutionManagerId, JobId, ResourceGroupId, TaskInstanceId},
id::{ExecutionManagerId, JobId, ResourceGroupId, TaskId, TaskInstanceId},
io::{ExecutionContext, TaskOutput},
},
};
use tokio::sync::{RwLockReadGuard, RwLockWriteGuard};

use crate::{
cache::{
TaskId,
error::{CacheError, InternalError, InternalError::UnexpectedJobState, StaleStateError},
job_submission::ValidatedJobSubmission,
task::TaskGraph,
Expand Down
3 changes: 1 addition & 2 deletions components/spider-storage/src/task_instance_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ use std::{
};

use async_trait::async_trait;
use spider_core::types::id::{ExecutionManagerId, JobId, ResourceGroupId, TaskInstanceId};
use spider_core::types::id::{ExecutionManagerId, JobId, ResourceGroupId, TaskId, TaskInstanceId};
use tokio::sync::mpsc;

use crate::{
cache::{
TaskId,
error::InternalError,
task::{SharedTaskControlBlock, SharedTerminationTaskControlBlock},
},
Expand Down
3 changes: 1 addition & 2 deletions components/spider-storage/tests/scheduling_infra.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,12 @@ use spider_core::{
job::JobState,
task::TaskIndex,
types::{
id::{ExecutionManagerId, JobId, ResourceGroupId, TaskInstanceId},
id::{ExecutionManagerId, JobId, ResourceGroupId, TaskId, TaskInstanceId},
io::{ExecutionContext, TaskOutput},
},
};
use spider_storage::{
cache::{
TaskId,
error::{CacheError, InternalError},
job::SharedJobControlBlock,
job_submission::ValidatedJobSubmission,
Expand Down
2 changes: 1 addition & 1 deletion components/spider-tdl/src/task.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ mod tests {
fn make_encoded_ctx() -> Vec<u8> {
let ctx = TaskContext {
job_id: JobId::new(),
task_id: TaskId::new(),
task_id: TaskId::Index(0),
task_instance_id: 1,
resource_group_id: ResourceGroupId::new(),
};
Expand Down
2 changes: 1 addition & 1 deletion components/spider-tdl/src/task_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ mod tests {
fn round_trip_msgpack() -> anyhow::Result<()> {
let ctx = TaskContext {
job_id: JobId::new(),
task_id: TaskId::new(),
task_id: TaskId::Index(0),
task_instance_id: 13,
resource_group_id: ResourceGroupId::new(),
};
Expand Down
4 changes: 2 additions & 2 deletions components/spider-tdl/tests/test_task_macro.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ fn translate(_ctx: TaskContext, p: Point, dx: int32, dy: int32) -> Result<(Point
fn make_encoded_ctx() -> Vec<u8> {
let ctx = TaskContext {
job_id: JobId::new(),
task_id: TaskId::new(),
task_id: TaskId::Index(0),
task_instance_id: 1,
resource_group_id: ResourceGroupId::new(),
};
Expand Down Expand Up @@ -303,7 +303,7 @@ fn direct_execute_call_round_trips() -> anyhow::Result<()> {

let ctx = TaskContext {
job_id: JobId::new(),
task_id: TaskId::new(),
task_id: TaskId::Index(0),
task_instance_id: 1,
resource_group_id: ResourceGroupId::new(),
};
Expand Down
2 changes: 1 addition & 1 deletion tests/huntsman/task-executor/tests/test_process_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn build_pool() -> ProcessPool {
fn make_request(task_func: &str, inputs: Vec<TaskInput>) -> ExecuteRequest {
ExecuteRequest {
job_id: JobId::new(),
task_id: TaskId::new(),
task_id: TaskId::Index(0),
resource_group_id: ResourceGroupId::new(),
ctx: ExecutionContext {
task_instance_id: 1,
Expand Down
2 changes: 1 addition & 1 deletion tests/huntsman/tdl-integration/tests/complex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ fn lib_path() -> std::path::PathBuf {
fn encode_ctx() -> Vec<u8> {
let ctx = TaskContext {
job_id: JobId::new(),
task_id: TaskId::new(),
task_id: TaskId::Index(0),
task_instance_id: 1,
resource_group_id: ResourceGroupId::new(),
};
Expand Down
2 changes: 1 addition & 1 deletion tests/huntsman/test-utils/src/executor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ pub fn tdl_package_dir() -> PathBuf {
pub fn build_ctx() -> Vec<u8> {
let ctx = TaskContext {
job_id: JobId::new(),
task_id: TaskId::new(),
task_id: TaskId::Index(0),
task_instance_id: 1,
resource_group_id: ResourceGroupId::new(),
};
Expand Down
Loading