Task Inheritance: Shared Context for Parent and Subtasks

Tl;dr

  • Users want to define context or configuration in a root task that can be accessed by all of its subtasks.

  • The current method of passing props through each level is cumbersome and leads to prop drilling.

  • Existing middleware doesn't solve this issue as each task run is executed on a separate sandboxed machine.


Description
Currently, users need to pass payload props from parent tasks to subtasks, which can be inefficient, especially for complex task hierarchies. While middleware exists, it doesn't provide a way to share context between a parent task and its subtasks across separate executions.


Proposed Solution

Implement a mechanism for "Task Inheritance" that allows a parent task to define a shared context or configuration that is automatically available to all of its subtasks, regardless of their execution environment.


Example

A parent task can define inheritable context/state that becomes available on called subtasks

// Example API (pseudo-code) 

task("parentTask", async (payload, { setInheritableContext }) => {
  // set fictive "onCacheHit" configuration for all subtasks
  setInheritableContext({ onCacheHit: "revalidate" });
  
  // call "subtask" here so that inheritedContext becomes available
  ...
};

task("subtask", async (payload, { inheritedContext }) => {
  const { onCacheHit } = inheritedContext; // Inherited context is available
  ...
};

Upvoters
Status

In Review

Board

πŸ’‘ Feature Request

Date

About 1 year ago

Author

Richard Poelderl

Subscribe to post

Get notified by email when there are changes.