feat: inserting and running sub-tasks dynamically
See original GitHub issueProblem
I’m creating a CLI to collect benchmarks, and I want to run a set of tasks n times. However, I don’t want to create a new task for each one as n could be as high as 100.
Instead, I want to use one task that repeats it’s sub-task n times, and updates the output message to Iteration ${i}
.
Feature request
An API like this where I can insert/run arbitrary Listr instances dynamically at run-time:
const listr = new Listr<Options>([
{
title: 'Benchmarking',
async task(context, task) {
for (let i = 0; i < 10; i++) {
task.output = `Iteration ${i}`;
// Run arbitrary listr instances as a sub-task
await task.run(task.newListr([
{
title: 'Task A',
task() { ... }
},
{
title: 'Task B',
task() { ... }
},
{
title: 'Task C',
task() { ... }
}
]));
}
}
},
...
]);
Issue Analytics
- State:
- Created 2 years ago
- Comments:10 (6 by maintainers)
Top Results From Across the Web
Dynamically create subtasks based on select list field
I have a custom field single check list and if a value is selected, I need to create a subtask based on the...
Read more >Notion 2.19, now with subtasks & dependencies
Click on Sub-items and go through the set-up flow. Hover over any database row, and then click on the toggle on the left...
Read more >Ansible subtasks with dynamic hosts - Stack Overflow
You can't include_tasks a playbook. include_tasks is used to include a tasklist (a list of tasks without hosts: ... and tasks: statements).
Read more >Dynamic Workflows - Flyte
Dynamic workflow is effectively both a task and a workflow. The key thing to note is that the _body of tasks is run...
Read more >Dynamic assignment of subtasks to reflect the assignee of the ...
In order to do this you can add a single-select custom field to the form. There list all your team members. Then set...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
No, it is actually not possible to run two listr at the same time because the problem is log-update takes control of the stdout and rest of the subtasks are always silent, so only the parent tasks get rendered. Elsewise the stdout gets corrupted as you say two instances taking control of it.
Oh, because in retries it won’t render the successful tasks that run before I suppose, I have to reset them to it should be a bug.
I will have a proper look at this tomorrow since it is kind of getting late here. Will prompt you how we can proceed if all is okay for you. But in the worst-case scenario we can have the rerun flag. But I think that this should somehow be possible to create something like this with the current form with some trickery.
I did a little more exploration and I decided to take another approach.
I withdraw my feature request but feel free to keep it open if you want to accommodate the potential use-case.
Thanks so much for your fast responses and support.