question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

feat: inserting and running sub-tasks dynamically

See original GitHub issue

Problem

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:closed
  • Created 2 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
cenk1cenk2commented, May 1, 2021

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.

1reaction
privatenumbercommented, May 2, 2021

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found