InfrastructureAsCode-ch / nornir_rich

29 stars 3 forks source link

Task Description on Progress Bar #5

Closed bfernando1 closed 2 years ago

bfernando1 commented 2 years ago

Feature Request I'd like to see the title: Overall Progress be substituted with the current task. This would help me see which task is being worked on.

ubaumann commented 2 years ago

Thank you for raising this feature request. To be sure I understand correctly. In this example, you want to see the title as "random_sleep"?

nr_with_processors = nr.with_processors([RichProgressBar()])
result = nr_with_processors.run(task=random_sleep)
bfernando1 commented 2 years ago

@ubaumann Yes, that's right! I think passing our own description for the task being run would be effective. That way we can freely re-use a task in different contexts with the progress bars.

dmzook commented 2 years ago

If we move some of the init tasks to start we could read task.name and use that value. This way it can be set simply by normal usage of nornir.run(name="some task name", task=sometask)

ubaumann commented 2 years ago

I made a quick test and put it in a pull request #6 Is it as you imagined it? I put both panels in a variable so that in the future we can also change the color of the panel from yellow to red as soon as a task fails or other functions.

from time import sleep
from nornir_rich.progress_bar import RichProgressBar

def random_sleep(task: Task) -> Result:
    delay = randrange(10)
    sleep(delay)
    return Result(host=task.host, result=f"{delay} seconds delay")

nr.data.reset_failed_hosts()
nr_with_processors = nr.with_processors([RichProgressBar()])
result = nr_with_processors.run(task=random_sleep)

image

dmzook commented 2 years ago

I like it. Nice work.

ubaumann commented 2 years ago

Merged. So I close this issue. Will try to realease a new release soon