You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.
[Maintainer edit: this ticket is now about all general "what is the overall execution system up to?" functionality - current task, that task's args, results of CLI parsing, etc]
I'd like to print a progress bar that shows how many tasks have completed and how many remain.
The API currently does not expose these statistics as far as I know.
Is there any way I'm not familiar with to count the number of pending and completed tasks?
The text was updated successfully, but these errors were encountered:
Nope, that's not implemented, but the statistics themselves would want to live in the Executor class most likely, and it would probably not be hard to just make it generally available to any code that has a handle on that object.
How to use the resulting data is a bit tougher since I assume you want either A) ability to access it within a task, via the context, or B) a general internal/core behavior where e.g. the Executor is itself displaying this progress bar as it goes.
I'm curious about your real-world use case! Most tasks I'm familiar with tend to have some output as they run (even if it's high level log-esque statements and not command stdout) so a progress bar doesn't work too well there, only if there is no other output.
(That said, I've experimented with a hybrid "one output line per task/subtask, and spinners/progress bars for commands that are known to take a long time" approach in some non-public tasks for my job, using libraries like humanfriendly and tdqm. Making those helper/util functions publicly available would be nice.)
Note to self, this may need a little bit of extension for Fabric as well, re: current host in a host list / current role / etc, though if those are couched in general enough terms (re: parameterization of a task) it may end up working 100% through the Invoke side of things.
Here's a way to access the current Call object in case anyone needs a workaround (you can also access calls from the same stack frame, which would allow a progress indicator):
# See https://www.fabfile.org/upgrading.html#fabric-env-reference
# and https://github.com/pyinvoke/invoke/issues/443
frame = inspect.currentframe().f_back
if "call" in frame.f_locals:
call = frame.f_locals["call"]
frame = frame.f_back
"get_current_task_name must be called in an invoke context",
I'm also looking at ways to communicate progress to the user while tasks run. Instead of a progress bar, I was thinking of something much simpler: when each task starts, Invoke prints a line "Task such-and-such starts" in the console, and perhaps a similar line when a task finishes. I can of course add my own print statement at the start of every task, but this could also be something that Invoke does (as an option, with a CLI flag like --log-progress or something like that).
The --debug parameter sort of does this, in the output I see lines like: