Skip to main content

TaskLookup

Struct TaskLookup 

Source
pub struct TaskLookup<'ws> {
    pub project: &'ws Project,
    pub task_def: &'ws Task,
    pub key: CacheKey,
    pub manifest: Option<Manifest>,
}
Expand description

Run one task per its workspace declaration, cache-aware.

Lifecycle:

  1. RunObserver::on_task_started fires.
  2. crate::cache_key::build_cache_key derives the key from task‘s declared inputs, env contribution, and hard-edge predecessors’ captured stream hashes.
  3. haz_cache::Cache::lookup is consulted:
    • On a hit, haz_cache::Cache::restore materialises the manifest’s outputs at their workspace-absolute paths; stdout and stderr flow through the observer; the function returns RunSource::CacheHit with the manifest’s recorded stream hashes.
    • On a miss, the function builds a crate::process::SpawnPlan from the task’s haz_domain::action::TaskAction and the effective env (CACHE-008 runtime view: allow-listed host values plus task overrides, override wins), spawns through spawner, captures both streams to memory, awaits exit, emits the streams through the observer, classifies per EXEC-009. On success the outputs are enumerated and haz_cache::Cache::store persists the entry. On failure no store fires.
  4. RunObserver::on_task_finished fires with the terminal CompletedRecord.

The function is async because spawning, waiting, and stream capture all use the tokio runtime. Filesystem and cache calls are sync and run on the calling worker thread; callers that want to off-load the cache-key derivation (which hashes input file bytes) and the store phase (which hashes output file bytes) from an async context can wrap the function in tokio::task::spawn_blocking – both phases dominate the runtime cost of a single-task lifecycle.

created_at_unix is caller-supplied so the function stays a pure function of its arguments: tests pin the value, the scheduler passes the current wall-clock time.

§Errors

Returns a RunTaskError for any executor-level failure (cache-key derivation, restore, spawn, wait, stream read, output resolution, store). Task-level failures (non-zero exit or signalled exit) are reported as Ok(CompletedRecord { state: Failed, .. }) per EXEC-009; the cache is not consulted for store in that branch (CACHE-018). Carrier for the borrows + computed values cache_lookup_phase hands back to the caller (typically the scheduler in crate::run_graph::run_graph).

The struct lets EXEC-007 step 1 (cache lookup) be performed independently of EXEC-007 step 2 (restore) and step 3 (spawn); the scheduler interposes its mutex-compatibility check between the lookup and the spawn branch.

Lifetime 'ws ties the project and task_def borrows to the workspace borrow held inside the supplying RunContext.

Fields§

§project: &'ws Project

Bearing project of task (looked up once so neither downstream branch has to repeat the search).

§task_def: &'ws Task

Bearing task definition (action, mutex, env, etc.).

§key: CacheKey

Computed cache key.

§manifest: Option<Manifest>

Manifest of the matching cache entry, if any. Some(_) drives the restore branch; None drives the spawn branch.

Trait Implementations§

Source§

impl<'ws> Debug for TaskLookup<'ws>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'ws> Freeze for TaskLookup<'ws>

§

impl<'ws> RefUnwindSafe for TaskLookup<'ws>

§

impl<'ws> Send for TaskLookup<'ws>

§

impl<'ws> Sync for TaskLookup<'ws>

§

impl<'ws> Unpin for TaskLookup<'ws>

§

impl<'ws> UnsafeUnpin for TaskLookup<'ws>

§

impl<'ws> UnwindSafe for TaskLookup<'ws>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V